• 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.bigqueryconnection.v1;
18 
19 import static com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient.ListConnectionsPagedResponse;
20 
21 import com.google.api.gax.core.NoCredentialsProvider;
22 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
23 import com.google.api.gax.httpjson.testing.MockHttpService;
24 import com.google.api.gax.rpc.ApiClientHeaderProvider;
25 import com.google.api.gax.rpc.ApiException;
26 import com.google.api.gax.rpc.ApiExceptionFactory;
27 import com.google.api.gax.rpc.InvalidArgumentException;
28 import com.google.api.gax.rpc.StatusCode;
29 import com.google.api.gax.rpc.testing.FakeStatusCode;
30 import com.google.api.resourcenames.ResourceName;
31 import com.google.cloud.bigquery.connection.v1.Connection;
32 import com.google.cloud.bigquery.connection.v1.ConnectionName;
33 import com.google.cloud.bigquery.connection.v1.ListConnectionsResponse;
34 import com.google.cloud.bigquery.connection.v1.LocationName;
35 import com.google.cloud.bigqueryconnection.v1.stub.HttpJsonConnectionServiceStub;
36 import com.google.common.collect.Lists;
37 import com.google.iam.v1.AuditConfig;
38 import com.google.iam.v1.Binding;
39 import com.google.iam.v1.GetPolicyOptions;
40 import com.google.iam.v1.Policy;
41 import com.google.iam.v1.TestIamPermissionsResponse;
42 import com.google.protobuf.ByteString;
43 import com.google.protobuf.Empty;
44 import com.google.protobuf.FieldMask;
45 import java.io.IOException;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.List;
49 import javax.annotation.Generated;
50 import org.junit.After;
51 import org.junit.AfterClass;
52 import org.junit.Assert;
53 import org.junit.Before;
54 import org.junit.BeforeClass;
55 import org.junit.Test;
56 
57 @Generated("by gapic-generator-java")
58 public class ConnectionServiceClientHttpJsonTest {
59   private static MockHttpService mockService;
60   private static ConnectionServiceClient client;
61 
62   @BeforeClass
startStaticServer()63   public static void startStaticServer() throws IOException {
64     mockService =
65         new MockHttpService(
66             HttpJsonConnectionServiceStub.getMethodDescriptors(),
67             ConnectionServiceSettings.getDefaultEndpoint());
68     ConnectionServiceSettings settings =
69         ConnectionServiceSettings.newHttpJsonBuilder()
70             .setTransportChannelProvider(
71                 ConnectionServiceSettings.defaultHttpJsonTransportProviderBuilder()
72                     .setHttpTransport(mockService)
73                     .build())
74             .setCredentialsProvider(NoCredentialsProvider.create())
75             .build();
76     client = ConnectionServiceClient.create(settings);
77   }
78 
79   @AfterClass
stopServer()80   public static void stopServer() {
81     client.close();
82   }
83 
84   @Before
setUp()85   public void setUp() {}
86 
87   @After
tearDown()88   public void tearDown() throws Exception {
89     mockService.reset();
90   }
91 
92   @Test
createConnectionTest()93   public void createConnectionTest() throws Exception {
94     Connection expectedResponse =
95         Connection.newBuilder()
96             .setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString())
97             .setFriendlyName("friendlyName461933014")
98             .setDescription("description-1724546052")
99             .setCreationTime(1932333101)
100             .setLastModifiedTime(-671513446)
101             .setHasCredential(true)
102             .build();
103     mockService.addResponse(expectedResponse);
104 
105     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
106     Connection connection = Connection.newBuilder().build();
107     String connectionId = "connectionId1923106969";
108 
109     Connection actualResponse = client.createConnection(parent, connection, connectionId);
110     Assert.assertEquals(expectedResponse, actualResponse);
111 
112     List<String> actualRequests = mockService.getRequestPaths();
113     Assert.assertEquals(1, actualRequests.size());
114 
115     String apiClientHeaderKey =
116         mockService
117             .getRequestHeaders()
118             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
119             .iterator()
120             .next();
121     Assert.assertTrue(
122         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
123             .matcher(apiClientHeaderKey)
124             .matches());
125   }
126 
127   @Test
createConnectionExceptionTest()128   public void createConnectionExceptionTest() throws Exception {
129     ApiException exception =
130         ApiExceptionFactory.createException(
131             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
132     mockService.addException(exception);
133 
134     try {
135       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
136       Connection connection = Connection.newBuilder().build();
137       String connectionId = "connectionId1923106969";
138       client.createConnection(parent, connection, connectionId);
139       Assert.fail("No exception raised");
140     } catch (InvalidArgumentException e) {
141       // Expected exception.
142     }
143   }
144 
145   @Test
createConnectionTest2()146   public void createConnectionTest2() throws Exception {
147     Connection expectedResponse =
148         Connection.newBuilder()
149             .setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString())
150             .setFriendlyName("friendlyName461933014")
151             .setDescription("description-1724546052")
152             .setCreationTime(1932333101)
153             .setLastModifiedTime(-671513446)
154             .setHasCredential(true)
155             .build();
156     mockService.addResponse(expectedResponse);
157 
158     String parent = "projects/project-5833/locations/location-5833";
159     Connection connection = Connection.newBuilder().build();
160     String connectionId = "connectionId1923106969";
161 
162     Connection actualResponse = client.createConnection(parent, connection, connectionId);
163     Assert.assertEquals(expectedResponse, actualResponse);
164 
165     List<String> actualRequests = mockService.getRequestPaths();
166     Assert.assertEquals(1, actualRequests.size());
167 
168     String apiClientHeaderKey =
169         mockService
170             .getRequestHeaders()
171             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
172             .iterator()
173             .next();
174     Assert.assertTrue(
175         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
176             .matcher(apiClientHeaderKey)
177             .matches());
178   }
179 
180   @Test
createConnectionExceptionTest2()181   public void createConnectionExceptionTest2() throws Exception {
182     ApiException exception =
183         ApiExceptionFactory.createException(
184             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
185     mockService.addException(exception);
186 
187     try {
188       String parent = "projects/project-5833/locations/location-5833";
189       Connection connection = Connection.newBuilder().build();
190       String connectionId = "connectionId1923106969";
191       client.createConnection(parent, connection, connectionId);
192       Assert.fail("No exception raised");
193     } catch (InvalidArgumentException e) {
194       // Expected exception.
195     }
196   }
197 
198   @Test
getConnectionTest()199   public void getConnectionTest() throws Exception {
200     Connection expectedResponse =
201         Connection.newBuilder()
202             .setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString())
203             .setFriendlyName("friendlyName461933014")
204             .setDescription("description-1724546052")
205             .setCreationTime(1932333101)
206             .setLastModifiedTime(-671513446)
207             .setHasCredential(true)
208             .build();
209     mockService.addResponse(expectedResponse);
210 
211     ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
212 
213     Connection actualResponse = client.getConnection(name);
214     Assert.assertEquals(expectedResponse, actualResponse);
215 
216     List<String> actualRequests = mockService.getRequestPaths();
217     Assert.assertEquals(1, actualRequests.size());
218 
219     String apiClientHeaderKey =
220         mockService
221             .getRequestHeaders()
222             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
223             .iterator()
224             .next();
225     Assert.assertTrue(
226         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
227             .matcher(apiClientHeaderKey)
228             .matches());
229   }
230 
231   @Test
getConnectionExceptionTest()232   public void getConnectionExceptionTest() throws Exception {
233     ApiException exception =
234         ApiExceptionFactory.createException(
235             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
236     mockService.addException(exception);
237 
238     try {
239       ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
240       client.getConnection(name);
241       Assert.fail("No exception raised");
242     } catch (InvalidArgumentException e) {
243       // Expected exception.
244     }
245   }
246 
247   @Test
getConnectionTest2()248   public void getConnectionTest2() throws Exception {
249     Connection expectedResponse =
250         Connection.newBuilder()
251             .setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString())
252             .setFriendlyName("friendlyName461933014")
253             .setDescription("description-1724546052")
254             .setCreationTime(1932333101)
255             .setLastModifiedTime(-671513446)
256             .setHasCredential(true)
257             .build();
258     mockService.addResponse(expectedResponse);
259 
260     String name = "projects/project-7851/locations/location-7851/connections/connection-7851";
261 
262     Connection actualResponse = client.getConnection(name);
263     Assert.assertEquals(expectedResponse, actualResponse);
264 
265     List<String> actualRequests = mockService.getRequestPaths();
266     Assert.assertEquals(1, actualRequests.size());
267 
268     String apiClientHeaderKey =
269         mockService
270             .getRequestHeaders()
271             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
272             .iterator()
273             .next();
274     Assert.assertTrue(
275         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
276             .matcher(apiClientHeaderKey)
277             .matches());
278   }
279 
280   @Test
getConnectionExceptionTest2()281   public void getConnectionExceptionTest2() throws Exception {
282     ApiException exception =
283         ApiExceptionFactory.createException(
284             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
285     mockService.addException(exception);
286 
287     try {
288       String name = "projects/project-7851/locations/location-7851/connections/connection-7851";
289       client.getConnection(name);
290       Assert.fail("No exception raised");
291     } catch (InvalidArgumentException e) {
292       // Expected exception.
293     }
294   }
295 
296   @Test
listConnectionsTest()297   public void listConnectionsTest() throws Exception {
298     Connection responsesElement = Connection.newBuilder().build();
299     ListConnectionsResponse expectedResponse =
300         ListConnectionsResponse.newBuilder()
301             .setNextPageToken("")
302             .addAllConnections(Arrays.asList(responsesElement))
303             .build();
304     mockService.addResponse(expectedResponse);
305 
306     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
307 
308     ListConnectionsPagedResponse pagedListResponse = client.listConnections(parent);
309 
310     List<Connection> resources = Lists.newArrayList(pagedListResponse.iterateAll());
311 
312     Assert.assertEquals(1, resources.size());
313     Assert.assertEquals(expectedResponse.getConnectionsList().get(0), resources.get(0));
314 
315     List<String> actualRequests = mockService.getRequestPaths();
316     Assert.assertEquals(1, actualRequests.size());
317 
318     String apiClientHeaderKey =
319         mockService
320             .getRequestHeaders()
321             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
322             .iterator()
323             .next();
324     Assert.assertTrue(
325         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
326             .matcher(apiClientHeaderKey)
327             .matches());
328   }
329 
330   @Test
listConnectionsExceptionTest()331   public void listConnectionsExceptionTest() throws Exception {
332     ApiException exception =
333         ApiExceptionFactory.createException(
334             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
335     mockService.addException(exception);
336 
337     try {
338       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
339       client.listConnections(parent);
340       Assert.fail("No exception raised");
341     } catch (InvalidArgumentException e) {
342       // Expected exception.
343     }
344   }
345 
346   @Test
listConnectionsTest2()347   public void listConnectionsTest2() throws Exception {
348     Connection responsesElement = Connection.newBuilder().build();
349     ListConnectionsResponse expectedResponse =
350         ListConnectionsResponse.newBuilder()
351             .setNextPageToken("")
352             .addAllConnections(Arrays.asList(responsesElement))
353             .build();
354     mockService.addResponse(expectedResponse);
355 
356     String parent = "projects/project-5833/locations/location-5833";
357 
358     ListConnectionsPagedResponse pagedListResponse = client.listConnections(parent);
359 
360     List<Connection> resources = Lists.newArrayList(pagedListResponse.iterateAll());
361 
362     Assert.assertEquals(1, resources.size());
363     Assert.assertEquals(expectedResponse.getConnectionsList().get(0), resources.get(0));
364 
365     List<String> actualRequests = mockService.getRequestPaths();
366     Assert.assertEquals(1, actualRequests.size());
367 
368     String apiClientHeaderKey =
369         mockService
370             .getRequestHeaders()
371             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
372             .iterator()
373             .next();
374     Assert.assertTrue(
375         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
376             .matcher(apiClientHeaderKey)
377             .matches());
378   }
379 
380   @Test
listConnectionsExceptionTest2()381   public void listConnectionsExceptionTest2() throws Exception {
382     ApiException exception =
383         ApiExceptionFactory.createException(
384             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
385     mockService.addException(exception);
386 
387     try {
388       String parent = "projects/project-5833/locations/location-5833";
389       client.listConnections(parent);
390       Assert.fail("No exception raised");
391     } catch (InvalidArgumentException e) {
392       // Expected exception.
393     }
394   }
395 
396   @Test
updateConnectionTest()397   public void updateConnectionTest() throws Exception {
398     Connection expectedResponse =
399         Connection.newBuilder()
400             .setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString())
401             .setFriendlyName("friendlyName461933014")
402             .setDescription("description-1724546052")
403             .setCreationTime(1932333101)
404             .setLastModifiedTime(-671513446)
405             .setHasCredential(true)
406             .build();
407     mockService.addResponse(expectedResponse);
408 
409     ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
410     Connection connection = Connection.newBuilder().build();
411     FieldMask updateMask = FieldMask.newBuilder().build();
412 
413     Connection actualResponse = client.updateConnection(name, connection, updateMask);
414     Assert.assertEquals(expectedResponse, actualResponse);
415 
416     List<String> actualRequests = mockService.getRequestPaths();
417     Assert.assertEquals(1, actualRequests.size());
418 
419     String apiClientHeaderKey =
420         mockService
421             .getRequestHeaders()
422             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
423             .iterator()
424             .next();
425     Assert.assertTrue(
426         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
427             .matcher(apiClientHeaderKey)
428             .matches());
429   }
430 
431   @Test
updateConnectionExceptionTest()432   public void updateConnectionExceptionTest() throws Exception {
433     ApiException exception =
434         ApiExceptionFactory.createException(
435             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
436     mockService.addException(exception);
437 
438     try {
439       ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
440       Connection connection = Connection.newBuilder().build();
441       FieldMask updateMask = FieldMask.newBuilder().build();
442       client.updateConnection(name, connection, updateMask);
443       Assert.fail("No exception raised");
444     } catch (InvalidArgumentException e) {
445       // Expected exception.
446     }
447   }
448 
449   @Test
updateConnectionTest2()450   public void updateConnectionTest2() throws Exception {
451     Connection expectedResponse =
452         Connection.newBuilder()
453             .setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString())
454             .setFriendlyName("friendlyName461933014")
455             .setDescription("description-1724546052")
456             .setCreationTime(1932333101)
457             .setLastModifiedTime(-671513446)
458             .setHasCredential(true)
459             .build();
460     mockService.addResponse(expectedResponse);
461 
462     String name = "projects/project-7851/locations/location-7851/connections/connection-7851";
463     Connection connection = Connection.newBuilder().build();
464     FieldMask updateMask = FieldMask.newBuilder().build();
465 
466     Connection actualResponse = client.updateConnection(name, connection, updateMask);
467     Assert.assertEquals(expectedResponse, actualResponse);
468 
469     List<String> actualRequests = mockService.getRequestPaths();
470     Assert.assertEquals(1, actualRequests.size());
471 
472     String apiClientHeaderKey =
473         mockService
474             .getRequestHeaders()
475             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
476             .iterator()
477             .next();
478     Assert.assertTrue(
479         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
480             .matcher(apiClientHeaderKey)
481             .matches());
482   }
483 
484   @Test
updateConnectionExceptionTest2()485   public void updateConnectionExceptionTest2() throws Exception {
486     ApiException exception =
487         ApiExceptionFactory.createException(
488             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
489     mockService.addException(exception);
490 
491     try {
492       String name = "projects/project-7851/locations/location-7851/connections/connection-7851";
493       Connection connection = Connection.newBuilder().build();
494       FieldMask updateMask = FieldMask.newBuilder().build();
495       client.updateConnection(name, connection, updateMask);
496       Assert.fail("No exception raised");
497     } catch (InvalidArgumentException e) {
498       // Expected exception.
499     }
500   }
501 
502   @Test
deleteConnectionTest()503   public void deleteConnectionTest() throws Exception {
504     Empty expectedResponse = Empty.newBuilder().build();
505     mockService.addResponse(expectedResponse);
506 
507     ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
508 
509     client.deleteConnection(name);
510 
511     List<String> actualRequests = mockService.getRequestPaths();
512     Assert.assertEquals(1, actualRequests.size());
513 
514     String apiClientHeaderKey =
515         mockService
516             .getRequestHeaders()
517             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
518             .iterator()
519             .next();
520     Assert.assertTrue(
521         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
522             .matcher(apiClientHeaderKey)
523             .matches());
524   }
525 
526   @Test
deleteConnectionExceptionTest()527   public void deleteConnectionExceptionTest() throws Exception {
528     ApiException exception =
529         ApiExceptionFactory.createException(
530             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
531     mockService.addException(exception);
532 
533     try {
534       ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
535       client.deleteConnection(name);
536       Assert.fail("No exception raised");
537     } catch (InvalidArgumentException e) {
538       // Expected exception.
539     }
540   }
541 
542   @Test
deleteConnectionTest2()543   public void deleteConnectionTest2() throws Exception {
544     Empty expectedResponse = Empty.newBuilder().build();
545     mockService.addResponse(expectedResponse);
546 
547     String name = "projects/project-7851/locations/location-7851/connections/connection-7851";
548 
549     client.deleteConnection(name);
550 
551     List<String> actualRequests = mockService.getRequestPaths();
552     Assert.assertEquals(1, actualRequests.size());
553 
554     String apiClientHeaderKey =
555         mockService
556             .getRequestHeaders()
557             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
558             .iterator()
559             .next();
560     Assert.assertTrue(
561         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
562             .matcher(apiClientHeaderKey)
563             .matches());
564   }
565 
566   @Test
deleteConnectionExceptionTest2()567   public void deleteConnectionExceptionTest2() throws Exception {
568     ApiException exception =
569         ApiExceptionFactory.createException(
570             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
571     mockService.addException(exception);
572 
573     try {
574       String name = "projects/project-7851/locations/location-7851/connections/connection-7851";
575       client.deleteConnection(name);
576       Assert.fail("No exception raised");
577     } catch (InvalidArgumentException e) {
578       // Expected exception.
579     }
580   }
581 
582   @Test
getIamPolicyTest()583   public void getIamPolicyTest() throws Exception {
584     Policy expectedResponse =
585         Policy.newBuilder()
586             .setVersion(351608024)
587             .addAllBindings(new ArrayList<Binding>())
588             .addAllAuditConfigs(new ArrayList<AuditConfig>())
589             .setEtag(ByteString.EMPTY)
590             .build();
591     mockService.addResponse(expectedResponse);
592 
593     ResourceName resource = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
594     GetPolicyOptions options = GetPolicyOptions.newBuilder().build();
595 
596     Policy actualResponse = client.getIamPolicy(resource, options);
597     Assert.assertEquals(expectedResponse, actualResponse);
598 
599     List<String> actualRequests = mockService.getRequestPaths();
600     Assert.assertEquals(1, actualRequests.size());
601 
602     String apiClientHeaderKey =
603         mockService
604             .getRequestHeaders()
605             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
606             .iterator()
607             .next();
608     Assert.assertTrue(
609         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
610             .matcher(apiClientHeaderKey)
611             .matches());
612   }
613 
614   @Test
getIamPolicyExceptionTest()615   public void getIamPolicyExceptionTest() throws Exception {
616     ApiException exception =
617         ApiExceptionFactory.createException(
618             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
619     mockService.addException(exception);
620 
621     try {
622       ResourceName resource = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
623       GetPolicyOptions options = GetPolicyOptions.newBuilder().build();
624       client.getIamPolicy(resource, options);
625       Assert.fail("No exception raised");
626     } catch (InvalidArgumentException e) {
627       // Expected exception.
628     }
629   }
630 
631   @Test
getIamPolicyTest2()632   public void getIamPolicyTest2() throws Exception {
633     Policy expectedResponse =
634         Policy.newBuilder()
635             .setVersion(351608024)
636             .addAllBindings(new ArrayList<Binding>())
637             .addAllAuditConfigs(new ArrayList<AuditConfig>())
638             .setEtag(ByteString.EMPTY)
639             .build();
640     mockService.addResponse(expectedResponse);
641 
642     String resource = "projects/project-9698/locations/location-9698/connections/connection-9698";
643     GetPolicyOptions options = GetPolicyOptions.newBuilder().build();
644 
645     Policy actualResponse = client.getIamPolicy(resource, options);
646     Assert.assertEquals(expectedResponse, actualResponse);
647 
648     List<String> actualRequests = mockService.getRequestPaths();
649     Assert.assertEquals(1, actualRequests.size());
650 
651     String apiClientHeaderKey =
652         mockService
653             .getRequestHeaders()
654             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
655             .iterator()
656             .next();
657     Assert.assertTrue(
658         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
659             .matcher(apiClientHeaderKey)
660             .matches());
661   }
662 
663   @Test
getIamPolicyExceptionTest2()664   public void getIamPolicyExceptionTest2() throws Exception {
665     ApiException exception =
666         ApiExceptionFactory.createException(
667             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
668     mockService.addException(exception);
669 
670     try {
671       String resource = "projects/project-9698/locations/location-9698/connections/connection-9698";
672       GetPolicyOptions options = GetPolicyOptions.newBuilder().build();
673       client.getIamPolicy(resource, options);
674       Assert.fail("No exception raised");
675     } catch (InvalidArgumentException e) {
676       // Expected exception.
677     }
678   }
679 
680   @Test
setIamPolicyTest()681   public void setIamPolicyTest() throws Exception {
682     Policy expectedResponse =
683         Policy.newBuilder()
684             .setVersion(351608024)
685             .addAllBindings(new ArrayList<Binding>())
686             .addAllAuditConfigs(new ArrayList<AuditConfig>())
687             .setEtag(ByteString.EMPTY)
688             .build();
689     mockService.addResponse(expectedResponse);
690 
691     ResourceName resource = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
692     Policy policy = Policy.newBuilder().build();
693 
694     Policy actualResponse = client.setIamPolicy(resource, policy);
695     Assert.assertEquals(expectedResponse, actualResponse);
696 
697     List<String> actualRequests = mockService.getRequestPaths();
698     Assert.assertEquals(1, actualRequests.size());
699 
700     String apiClientHeaderKey =
701         mockService
702             .getRequestHeaders()
703             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
704             .iterator()
705             .next();
706     Assert.assertTrue(
707         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
708             .matcher(apiClientHeaderKey)
709             .matches());
710   }
711 
712   @Test
setIamPolicyExceptionTest()713   public void setIamPolicyExceptionTest() throws Exception {
714     ApiException exception =
715         ApiExceptionFactory.createException(
716             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
717     mockService.addException(exception);
718 
719     try {
720       ResourceName resource = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
721       Policy policy = Policy.newBuilder().build();
722       client.setIamPolicy(resource, policy);
723       Assert.fail("No exception raised");
724     } catch (InvalidArgumentException e) {
725       // Expected exception.
726     }
727   }
728 
729   @Test
setIamPolicyTest2()730   public void setIamPolicyTest2() throws Exception {
731     Policy expectedResponse =
732         Policy.newBuilder()
733             .setVersion(351608024)
734             .addAllBindings(new ArrayList<Binding>())
735             .addAllAuditConfigs(new ArrayList<AuditConfig>())
736             .setEtag(ByteString.EMPTY)
737             .build();
738     mockService.addResponse(expectedResponse);
739 
740     String resource = "projects/project-9698/locations/location-9698/connections/connection-9698";
741     Policy policy = Policy.newBuilder().build();
742 
743     Policy actualResponse = client.setIamPolicy(resource, policy);
744     Assert.assertEquals(expectedResponse, actualResponse);
745 
746     List<String> actualRequests = mockService.getRequestPaths();
747     Assert.assertEquals(1, actualRequests.size());
748 
749     String apiClientHeaderKey =
750         mockService
751             .getRequestHeaders()
752             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
753             .iterator()
754             .next();
755     Assert.assertTrue(
756         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
757             .matcher(apiClientHeaderKey)
758             .matches());
759   }
760 
761   @Test
setIamPolicyExceptionTest2()762   public void setIamPolicyExceptionTest2() throws Exception {
763     ApiException exception =
764         ApiExceptionFactory.createException(
765             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
766     mockService.addException(exception);
767 
768     try {
769       String resource = "projects/project-9698/locations/location-9698/connections/connection-9698";
770       Policy policy = Policy.newBuilder().build();
771       client.setIamPolicy(resource, policy);
772       Assert.fail("No exception raised");
773     } catch (InvalidArgumentException e) {
774       // Expected exception.
775     }
776   }
777 
778   @Test
testIamPermissionsTest()779   public void testIamPermissionsTest() throws Exception {
780     TestIamPermissionsResponse expectedResponse =
781         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
782     mockService.addResponse(expectedResponse);
783 
784     ResourceName resource = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
785     List<String> permissions = new ArrayList<>();
786 
787     TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions);
788     Assert.assertEquals(expectedResponse, actualResponse);
789 
790     List<String> actualRequests = mockService.getRequestPaths();
791     Assert.assertEquals(1, actualRequests.size());
792 
793     String apiClientHeaderKey =
794         mockService
795             .getRequestHeaders()
796             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
797             .iterator()
798             .next();
799     Assert.assertTrue(
800         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
801             .matcher(apiClientHeaderKey)
802             .matches());
803   }
804 
805   @Test
testIamPermissionsExceptionTest()806   public void testIamPermissionsExceptionTest() throws Exception {
807     ApiException exception =
808         ApiExceptionFactory.createException(
809             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
810     mockService.addException(exception);
811 
812     try {
813       ResourceName resource = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
814       List<String> permissions = new ArrayList<>();
815       client.testIamPermissions(resource, permissions);
816       Assert.fail("No exception raised");
817     } catch (InvalidArgumentException e) {
818       // Expected exception.
819     }
820   }
821 
822   @Test
testIamPermissionsTest2()823   public void testIamPermissionsTest2() throws Exception {
824     TestIamPermissionsResponse expectedResponse =
825         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
826     mockService.addResponse(expectedResponse);
827 
828     String resource = "projects/project-9698/locations/location-9698/connections/connection-9698";
829     List<String> permissions = new ArrayList<>();
830 
831     TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions);
832     Assert.assertEquals(expectedResponse, actualResponse);
833 
834     List<String> actualRequests = mockService.getRequestPaths();
835     Assert.assertEquals(1, actualRequests.size());
836 
837     String apiClientHeaderKey =
838         mockService
839             .getRequestHeaders()
840             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
841             .iterator()
842             .next();
843     Assert.assertTrue(
844         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
845             .matcher(apiClientHeaderKey)
846             .matches());
847   }
848 
849   @Test
testIamPermissionsExceptionTest2()850   public void testIamPermissionsExceptionTest2() throws Exception {
851     ApiException exception =
852         ApiExceptionFactory.createException(
853             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
854     mockService.addException(exception);
855 
856     try {
857       String resource = "projects/project-9698/locations/location-9698/connections/connection-9698";
858       List<String> permissions = new ArrayList<>();
859       client.testIamPermissions(resource, permissions);
860       Assert.fail("No exception raised");
861     } catch (InvalidArgumentException e) {
862       // Expected exception.
863     }
864   }
865 }
866