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