• 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.devtools.artifactregistry.v1;
18 
19 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListDockerImagesPagedResponse;
20 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListFilesPagedResponse;
21 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListLocationsPagedResponse;
22 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListMavenArtifactsPagedResponse;
23 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListNpmPackagesPagedResponse;
24 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListPackagesPagedResponse;
25 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListPythonPackagesPagedResponse;
26 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListRepositoriesPagedResponse;
27 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListTagsPagedResponse;
28 import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListVersionsPagedResponse;
29 
30 import com.google.api.gax.core.NoCredentialsProvider;
31 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
32 import com.google.api.gax.httpjson.testing.MockHttpService;
33 import com.google.api.gax.rpc.ApiClientHeaderProvider;
34 import com.google.api.gax.rpc.ApiException;
35 import com.google.api.gax.rpc.ApiExceptionFactory;
36 import com.google.api.gax.rpc.InvalidArgumentException;
37 import com.google.api.gax.rpc.StatusCode;
38 import com.google.api.gax.rpc.testing.FakeStatusCode;
39 import com.google.cloud.location.GetLocationRequest;
40 import com.google.cloud.location.ListLocationsRequest;
41 import com.google.cloud.location.ListLocationsResponse;
42 import com.google.cloud.location.Location;
43 import com.google.common.collect.Lists;
44 import com.google.devtools.artifactregistry.v1.stub.HttpJsonArtifactRegistryStub;
45 import com.google.iam.v1.AuditConfig;
46 import com.google.iam.v1.Binding;
47 import com.google.iam.v1.GetIamPolicyRequest;
48 import com.google.iam.v1.GetPolicyOptions;
49 import com.google.iam.v1.Policy;
50 import com.google.iam.v1.SetIamPolicyRequest;
51 import com.google.iam.v1.TestIamPermissionsRequest;
52 import com.google.iam.v1.TestIamPermissionsResponse;
53 import com.google.longrunning.Operation;
54 import com.google.protobuf.Any;
55 import com.google.protobuf.ByteString;
56 import com.google.protobuf.Empty;
57 import com.google.protobuf.FieldMask;
58 import com.google.protobuf.Struct;
59 import com.google.protobuf.Timestamp;
60 import java.io.IOException;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.HashMap;
64 import java.util.List;
65 import java.util.concurrent.ExecutionException;
66 import javax.annotation.Generated;
67 import org.junit.After;
68 import org.junit.AfterClass;
69 import org.junit.Assert;
70 import org.junit.Before;
71 import org.junit.BeforeClass;
72 import org.junit.Test;
73 
74 @Generated("by gapic-generator-java")
75 public class ArtifactRegistryClientHttpJsonTest {
76   private static MockHttpService mockService;
77   private static ArtifactRegistryClient client;
78 
79   @BeforeClass
startStaticServer()80   public static void startStaticServer() throws IOException {
81     mockService =
82         new MockHttpService(
83             HttpJsonArtifactRegistryStub.getMethodDescriptors(),
84             ArtifactRegistrySettings.getDefaultEndpoint());
85     ArtifactRegistrySettings settings =
86         ArtifactRegistrySettings.newHttpJsonBuilder()
87             .setTransportChannelProvider(
88                 ArtifactRegistrySettings.defaultHttpJsonTransportProviderBuilder()
89                     .setHttpTransport(mockService)
90                     .build())
91             .setCredentialsProvider(NoCredentialsProvider.create())
92             .build();
93     client = ArtifactRegistryClient.create(settings);
94   }
95 
96   @AfterClass
stopServer()97   public static void stopServer() {
98     client.close();
99   }
100 
101   @Before
setUp()102   public void setUp() {}
103 
104   @After
tearDown()105   public void tearDown() throws Exception {
106     mockService.reset();
107   }
108 
109   @Test
listDockerImagesTest()110   public void listDockerImagesTest() throws Exception {
111     DockerImage responsesElement = DockerImage.newBuilder().build();
112     ListDockerImagesResponse expectedResponse =
113         ListDockerImagesResponse.newBuilder()
114             .setNextPageToken("")
115             .addAllDockerImages(Arrays.asList(responsesElement))
116             .build();
117     mockService.addResponse(expectedResponse);
118 
119     String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
120 
121     ListDockerImagesPagedResponse pagedListResponse = client.listDockerImages(parent);
122 
123     List<DockerImage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
124 
125     Assert.assertEquals(1, resources.size());
126     Assert.assertEquals(expectedResponse.getDockerImagesList().get(0), resources.get(0));
127 
128     List<String> actualRequests = mockService.getRequestPaths();
129     Assert.assertEquals(1, actualRequests.size());
130 
131     String apiClientHeaderKey =
132         mockService
133             .getRequestHeaders()
134             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
135             .iterator()
136             .next();
137     Assert.assertTrue(
138         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
139             .matcher(apiClientHeaderKey)
140             .matches());
141   }
142 
143   @Test
listDockerImagesExceptionTest()144   public void listDockerImagesExceptionTest() throws Exception {
145     ApiException exception =
146         ApiExceptionFactory.createException(
147             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
148     mockService.addException(exception);
149 
150     try {
151       String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
152       client.listDockerImages(parent);
153       Assert.fail("No exception raised");
154     } catch (InvalidArgumentException e) {
155       // Expected exception.
156     }
157   }
158 
159   @Test
getDockerImageTest()160   public void getDockerImageTest() throws Exception {
161     DockerImage expectedResponse =
162         DockerImage.newBuilder()
163             .setName(
164                 DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]")
165                     .toString())
166             .setUri("uri116076")
167             .addAllTags(new ArrayList<String>())
168             .setImageSizeBytes(837030929)
169             .setUploadTime(Timestamp.newBuilder().build())
170             .setMediaType("mediaType2140463422")
171             .setBuildTime(Timestamp.newBuilder().build())
172             .setUpdateTime(Timestamp.newBuilder().build())
173             .build();
174     mockService.addResponse(expectedResponse);
175 
176     DockerImageName name =
177         DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]");
178 
179     DockerImage actualResponse = client.getDockerImage(name);
180     Assert.assertEquals(expectedResponse, actualResponse);
181 
182     List<String> actualRequests = mockService.getRequestPaths();
183     Assert.assertEquals(1, actualRequests.size());
184 
185     String apiClientHeaderKey =
186         mockService
187             .getRequestHeaders()
188             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
189             .iterator()
190             .next();
191     Assert.assertTrue(
192         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
193             .matcher(apiClientHeaderKey)
194             .matches());
195   }
196 
197   @Test
getDockerImageExceptionTest()198   public void getDockerImageExceptionTest() throws Exception {
199     ApiException exception =
200         ApiExceptionFactory.createException(
201             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
202     mockService.addException(exception);
203 
204     try {
205       DockerImageName name =
206           DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]");
207       client.getDockerImage(name);
208       Assert.fail("No exception raised");
209     } catch (InvalidArgumentException e) {
210       // Expected exception.
211     }
212   }
213 
214   @Test
getDockerImageTest2()215   public void getDockerImageTest2() throws Exception {
216     DockerImage expectedResponse =
217         DockerImage.newBuilder()
218             .setName(
219                 DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]")
220                     .toString())
221             .setUri("uri116076")
222             .addAllTags(new ArrayList<String>())
223             .setImageSizeBytes(837030929)
224             .setUploadTime(Timestamp.newBuilder().build())
225             .setMediaType("mediaType2140463422")
226             .setBuildTime(Timestamp.newBuilder().build())
227             .setUpdateTime(Timestamp.newBuilder().build())
228             .build();
229     mockService.addResponse(expectedResponse);
230 
231     String name =
232         "projects/project-1270/locations/location-1270/repositories/repositorie-1270/dockerImages/dockerImage-1270";
233 
234     DockerImage actualResponse = client.getDockerImage(name);
235     Assert.assertEquals(expectedResponse, actualResponse);
236 
237     List<String> actualRequests = mockService.getRequestPaths();
238     Assert.assertEquals(1, actualRequests.size());
239 
240     String apiClientHeaderKey =
241         mockService
242             .getRequestHeaders()
243             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
244             .iterator()
245             .next();
246     Assert.assertTrue(
247         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
248             .matcher(apiClientHeaderKey)
249             .matches());
250   }
251 
252   @Test
getDockerImageExceptionTest2()253   public void getDockerImageExceptionTest2() throws Exception {
254     ApiException exception =
255         ApiExceptionFactory.createException(
256             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
257     mockService.addException(exception);
258 
259     try {
260       String name =
261           "projects/project-1270/locations/location-1270/repositories/repositorie-1270/dockerImages/dockerImage-1270";
262       client.getDockerImage(name);
263       Assert.fail("No exception raised");
264     } catch (InvalidArgumentException e) {
265       // Expected exception.
266     }
267   }
268 
269   @Test
listMavenArtifactsTest()270   public void listMavenArtifactsTest() throws Exception {
271     MavenArtifact responsesElement = MavenArtifact.newBuilder().build();
272     ListMavenArtifactsResponse expectedResponse =
273         ListMavenArtifactsResponse.newBuilder()
274             .setNextPageToken("")
275             .addAllMavenArtifacts(Arrays.asList(responsesElement))
276             .build();
277     mockService.addResponse(expectedResponse);
278 
279     RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
280 
281     ListMavenArtifactsPagedResponse pagedListResponse = client.listMavenArtifacts(parent);
282 
283     List<MavenArtifact> resources = Lists.newArrayList(pagedListResponse.iterateAll());
284 
285     Assert.assertEquals(1, resources.size());
286     Assert.assertEquals(expectedResponse.getMavenArtifactsList().get(0), resources.get(0));
287 
288     List<String> actualRequests = mockService.getRequestPaths();
289     Assert.assertEquals(1, actualRequests.size());
290 
291     String apiClientHeaderKey =
292         mockService
293             .getRequestHeaders()
294             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
295             .iterator()
296             .next();
297     Assert.assertTrue(
298         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
299             .matcher(apiClientHeaderKey)
300             .matches());
301   }
302 
303   @Test
listMavenArtifactsExceptionTest()304   public void listMavenArtifactsExceptionTest() throws Exception {
305     ApiException exception =
306         ApiExceptionFactory.createException(
307             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
308     mockService.addException(exception);
309 
310     try {
311       RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
312       client.listMavenArtifacts(parent);
313       Assert.fail("No exception raised");
314     } catch (InvalidArgumentException e) {
315       // Expected exception.
316     }
317   }
318 
319   @Test
listMavenArtifactsTest2()320   public void listMavenArtifactsTest2() throws Exception {
321     MavenArtifact responsesElement = MavenArtifact.newBuilder().build();
322     ListMavenArtifactsResponse expectedResponse =
323         ListMavenArtifactsResponse.newBuilder()
324             .setNextPageToken("")
325             .addAllMavenArtifacts(Arrays.asList(responsesElement))
326             .build();
327     mockService.addResponse(expectedResponse);
328 
329     String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
330 
331     ListMavenArtifactsPagedResponse pagedListResponse = client.listMavenArtifacts(parent);
332 
333     List<MavenArtifact> resources = Lists.newArrayList(pagedListResponse.iterateAll());
334 
335     Assert.assertEquals(1, resources.size());
336     Assert.assertEquals(expectedResponse.getMavenArtifactsList().get(0), resources.get(0));
337 
338     List<String> actualRequests = mockService.getRequestPaths();
339     Assert.assertEquals(1, actualRequests.size());
340 
341     String apiClientHeaderKey =
342         mockService
343             .getRequestHeaders()
344             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
345             .iterator()
346             .next();
347     Assert.assertTrue(
348         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
349             .matcher(apiClientHeaderKey)
350             .matches());
351   }
352 
353   @Test
listMavenArtifactsExceptionTest2()354   public void listMavenArtifactsExceptionTest2() throws Exception {
355     ApiException exception =
356         ApiExceptionFactory.createException(
357             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
358     mockService.addException(exception);
359 
360     try {
361       String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
362       client.listMavenArtifacts(parent);
363       Assert.fail("No exception raised");
364     } catch (InvalidArgumentException e) {
365       // Expected exception.
366     }
367   }
368 
369   @Test
getMavenArtifactTest()370   public void getMavenArtifactTest() throws Exception {
371     MavenArtifact expectedResponse =
372         MavenArtifact.newBuilder()
373             .setName(
374                 MavenArtifactName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[MAVEN_ARTIFACT]")
375                     .toString())
376             .setPomUri("pomUri-982659010")
377             .setGroupId("groupId293428218")
378             .setArtifactId("artifactId240640653")
379             .setVersion("version351608024")
380             .setCreateTime(Timestamp.newBuilder().build())
381             .setUpdateTime(Timestamp.newBuilder().build())
382             .build();
383     mockService.addResponse(expectedResponse);
384 
385     MavenArtifactName name =
386         MavenArtifactName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[MAVEN_ARTIFACT]");
387 
388     MavenArtifact actualResponse = client.getMavenArtifact(name);
389     Assert.assertEquals(expectedResponse, actualResponse);
390 
391     List<String> actualRequests = mockService.getRequestPaths();
392     Assert.assertEquals(1, actualRequests.size());
393 
394     String apiClientHeaderKey =
395         mockService
396             .getRequestHeaders()
397             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
398             .iterator()
399             .next();
400     Assert.assertTrue(
401         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
402             .matcher(apiClientHeaderKey)
403             .matches());
404   }
405 
406   @Test
getMavenArtifactExceptionTest()407   public void getMavenArtifactExceptionTest() throws Exception {
408     ApiException exception =
409         ApiExceptionFactory.createException(
410             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
411     mockService.addException(exception);
412 
413     try {
414       MavenArtifactName name =
415           MavenArtifactName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[MAVEN_ARTIFACT]");
416       client.getMavenArtifact(name);
417       Assert.fail("No exception raised");
418     } catch (InvalidArgumentException e) {
419       // Expected exception.
420     }
421   }
422 
423   @Test
getMavenArtifactTest2()424   public void getMavenArtifactTest2() throws Exception {
425     MavenArtifact expectedResponse =
426         MavenArtifact.newBuilder()
427             .setName(
428                 MavenArtifactName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[MAVEN_ARTIFACT]")
429                     .toString())
430             .setPomUri("pomUri-982659010")
431             .setGroupId("groupId293428218")
432             .setArtifactId("artifactId240640653")
433             .setVersion("version351608024")
434             .setCreateTime(Timestamp.newBuilder().build())
435             .setUpdateTime(Timestamp.newBuilder().build())
436             .build();
437     mockService.addResponse(expectedResponse);
438 
439     String name =
440         "projects/project-6824/locations/location-6824/repositories/repositorie-6824/mavenArtifacts/mavenArtifact-6824";
441 
442     MavenArtifact actualResponse = client.getMavenArtifact(name);
443     Assert.assertEquals(expectedResponse, actualResponse);
444 
445     List<String> actualRequests = mockService.getRequestPaths();
446     Assert.assertEquals(1, actualRequests.size());
447 
448     String apiClientHeaderKey =
449         mockService
450             .getRequestHeaders()
451             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
452             .iterator()
453             .next();
454     Assert.assertTrue(
455         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
456             .matcher(apiClientHeaderKey)
457             .matches());
458   }
459 
460   @Test
getMavenArtifactExceptionTest2()461   public void getMavenArtifactExceptionTest2() throws Exception {
462     ApiException exception =
463         ApiExceptionFactory.createException(
464             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
465     mockService.addException(exception);
466 
467     try {
468       String name =
469           "projects/project-6824/locations/location-6824/repositories/repositorie-6824/mavenArtifacts/mavenArtifact-6824";
470       client.getMavenArtifact(name);
471       Assert.fail("No exception raised");
472     } catch (InvalidArgumentException e) {
473       // Expected exception.
474     }
475   }
476 
477   @Test
listNpmPackagesTest()478   public void listNpmPackagesTest() throws Exception {
479     NpmPackage responsesElement = NpmPackage.newBuilder().build();
480     ListNpmPackagesResponse expectedResponse =
481         ListNpmPackagesResponse.newBuilder()
482             .setNextPageToken("")
483             .addAllNpmPackages(Arrays.asList(responsesElement))
484             .build();
485     mockService.addResponse(expectedResponse);
486 
487     RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
488 
489     ListNpmPackagesPagedResponse pagedListResponse = client.listNpmPackages(parent);
490 
491     List<NpmPackage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
492 
493     Assert.assertEquals(1, resources.size());
494     Assert.assertEquals(expectedResponse.getNpmPackagesList().get(0), resources.get(0));
495 
496     List<String> actualRequests = mockService.getRequestPaths();
497     Assert.assertEquals(1, actualRequests.size());
498 
499     String apiClientHeaderKey =
500         mockService
501             .getRequestHeaders()
502             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
503             .iterator()
504             .next();
505     Assert.assertTrue(
506         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
507             .matcher(apiClientHeaderKey)
508             .matches());
509   }
510 
511   @Test
listNpmPackagesExceptionTest()512   public void listNpmPackagesExceptionTest() throws Exception {
513     ApiException exception =
514         ApiExceptionFactory.createException(
515             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
516     mockService.addException(exception);
517 
518     try {
519       RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
520       client.listNpmPackages(parent);
521       Assert.fail("No exception raised");
522     } catch (InvalidArgumentException e) {
523       // Expected exception.
524     }
525   }
526 
527   @Test
listNpmPackagesTest2()528   public void listNpmPackagesTest2() throws Exception {
529     NpmPackage responsesElement = NpmPackage.newBuilder().build();
530     ListNpmPackagesResponse expectedResponse =
531         ListNpmPackagesResponse.newBuilder()
532             .setNextPageToken("")
533             .addAllNpmPackages(Arrays.asList(responsesElement))
534             .build();
535     mockService.addResponse(expectedResponse);
536 
537     String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
538 
539     ListNpmPackagesPagedResponse pagedListResponse = client.listNpmPackages(parent);
540 
541     List<NpmPackage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
542 
543     Assert.assertEquals(1, resources.size());
544     Assert.assertEquals(expectedResponse.getNpmPackagesList().get(0), resources.get(0));
545 
546     List<String> actualRequests = mockService.getRequestPaths();
547     Assert.assertEquals(1, actualRequests.size());
548 
549     String apiClientHeaderKey =
550         mockService
551             .getRequestHeaders()
552             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
553             .iterator()
554             .next();
555     Assert.assertTrue(
556         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
557             .matcher(apiClientHeaderKey)
558             .matches());
559   }
560 
561   @Test
listNpmPackagesExceptionTest2()562   public void listNpmPackagesExceptionTest2() throws Exception {
563     ApiException exception =
564         ApiExceptionFactory.createException(
565             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
566     mockService.addException(exception);
567 
568     try {
569       String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
570       client.listNpmPackages(parent);
571       Assert.fail("No exception raised");
572     } catch (InvalidArgumentException e) {
573       // Expected exception.
574     }
575   }
576 
577   @Test
getNpmPackageTest()578   public void getNpmPackageTest() throws Exception {
579     NpmPackage expectedResponse =
580         NpmPackage.newBuilder()
581             .setName(
582                 NpmPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[NPM_PACKAGE]")
583                     .toString())
584             .setPackageName("packageName908759025")
585             .setVersion("version351608024")
586             .addAllTags(new ArrayList<String>())
587             .setCreateTime(Timestamp.newBuilder().build())
588             .setUpdateTime(Timestamp.newBuilder().build())
589             .build();
590     mockService.addResponse(expectedResponse);
591 
592     NpmPackageName name =
593         NpmPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[NPM_PACKAGE]");
594 
595     NpmPackage actualResponse = client.getNpmPackage(name);
596     Assert.assertEquals(expectedResponse, actualResponse);
597 
598     List<String> actualRequests = mockService.getRequestPaths();
599     Assert.assertEquals(1, actualRequests.size());
600 
601     String apiClientHeaderKey =
602         mockService
603             .getRequestHeaders()
604             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
605             .iterator()
606             .next();
607     Assert.assertTrue(
608         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
609             .matcher(apiClientHeaderKey)
610             .matches());
611   }
612 
613   @Test
getNpmPackageExceptionTest()614   public void getNpmPackageExceptionTest() throws Exception {
615     ApiException exception =
616         ApiExceptionFactory.createException(
617             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
618     mockService.addException(exception);
619 
620     try {
621       NpmPackageName name =
622           NpmPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[NPM_PACKAGE]");
623       client.getNpmPackage(name);
624       Assert.fail("No exception raised");
625     } catch (InvalidArgumentException e) {
626       // Expected exception.
627     }
628   }
629 
630   @Test
getNpmPackageTest2()631   public void getNpmPackageTest2() throws Exception {
632     NpmPackage expectedResponse =
633         NpmPackage.newBuilder()
634             .setName(
635                 NpmPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[NPM_PACKAGE]")
636                     .toString())
637             .setPackageName("packageName908759025")
638             .setVersion("version351608024")
639             .addAllTags(new ArrayList<String>())
640             .setCreateTime(Timestamp.newBuilder().build())
641             .setUpdateTime(Timestamp.newBuilder().build())
642             .build();
643     mockService.addResponse(expectedResponse);
644 
645     String name =
646         "projects/project-2716/locations/location-2716/repositories/repositorie-2716/npmPackages/npmPackage-2716";
647 
648     NpmPackage actualResponse = client.getNpmPackage(name);
649     Assert.assertEquals(expectedResponse, actualResponse);
650 
651     List<String> actualRequests = mockService.getRequestPaths();
652     Assert.assertEquals(1, actualRequests.size());
653 
654     String apiClientHeaderKey =
655         mockService
656             .getRequestHeaders()
657             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
658             .iterator()
659             .next();
660     Assert.assertTrue(
661         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
662             .matcher(apiClientHeaderKey)
663             .matches());
664   }
665 
666   @Test
getNpmPackageExceptionTest2()667   public void getNpmPackageExceptionTest2() throws Exception {
668     ApiException exception =
669         ApiExceptionFactory.createException(
670             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
671     mockService.addException(exception);
672 
673     try {
674       String name =
675           "projects/project-2716/locations/location-2716/repositories/repositorie-2716/npmPackages/npmPackage-2716";
676       client.getNpmPackage(name);
677       Assert.fail("No exception raised");
678     } catch (InvalidArgumentException e) {
679       // Expected exception.
680     }
681   }
682 
683   @Test
listPythonPackagesTest()684   public void listPythonPackagesTest() throws Exception {
685     PythonPackage responsesElement = PythonPackage.newBuilder().build();
686     ListPythonPackagesResponse expectedResponse =
687         ListPythonPackagesResponse.newBuilder()
688             .setNextPageToken("")
689             .addAllPythonPackages(Arrays.asList(responsesElement))
690             .build();
691     mockService.addResponse(expectedResponse);
692 
693     RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
694 
695     ListPythonPackagesPagedResponse pagedListResponse = client.listPythonPackages(parent);
696 
697     List<PythonPackage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
698 
699     Assert.assertEquals(1, resources.size());
700     Assert.assertEquals(expectedResponse.getPythonPackagesList().get(0), resources.get(0));
701 
702     List<String> actualRequests = mockService.getRequestPaths();
703     Assert.assertEquals(1, actualRequests.size());
704 
705     String apiClientHeaderKey =
706         mockService
707             .getRequestHeaders()
708             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
709             .iterator()
710             .next();
711     Assert.assertTrue(
712         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
713             .matcher(apiClientHeaderKey)
714             .matches());
715   }
716 
717   @Test
listPythonPackagesExceptionTest()718   public void listPythonPackagesExceptionTest() throws Exception {
719     ApiException exception =
720         ApiExceptionFactory.createException(
721             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
722     mockService.addException(exception);
723 
724     try {
725       RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
726       client.listPythonPackages(parent);
727       Assert.fail("No exception raised");
728     } catch (InvalidArgumentException e) {
729       // Expected exception.
730     }
731   }
732 
733   @Test
listPythonPackagesTest2()734   public void listPythonPackagesTest2() throws Exception {
735     PythonPackage responsesElement = PythonPackage.newBuilder().build();
736     ListPythonPackagesResponse expectedResponse =
737         ListPythonPackagesResponse.newBuilder()
738             .setNextPageToken("")
739             .addAllPythonPackages(Arrays.asList(responsesElement))
740             .build();
741     mockService.addResponse(expectedResponse);
742 
743     String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
744 
745     ListPythonPackagesPagedResponse pagedListResponse = client.listPythonPackages(parent);
746 
747     List<PythonPackage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
748 
749     Assert.assertEquals(1, resources.size());
750     Assert.assertEquals(expectedResponse.getPythonPackagesList().get(0), resources.get(0));
751 
752     List<String> actualRequests = mockService.getRequestPaths();
753     Assert.assertEquals(1, actualRequests.size());
754 
755     String apiClientHeaderKey =
756         mockService
757             .getRequestHeaders()
758             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
759             .iterator()
760             .next();
761     Assert.assertTrue(
762         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
763             .matcher(apiClientHeaderKey)
764             .matches());
765   }
766 
767   @Test
listPythonPackagesExceptionTest2()768   public void listPythonPackagesExceptionTest2() throws Exception {
769     ApiException exception =
770         ApiExceptionFactory.createException(
771             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
772     mockService.addException(exception);
773 
774     try {
775       String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
776       client.listPythonPackages(parent);
777       Assert.fail("No exception raised");
778     } catch (InvalidArgumentException e) {
779       // Expected exception.
780     }
781   }
782 
783   @Test
getPythonPackageTest()784   public void getPythonPackageTest() throws Exception {
785     PythonPackage expectedResponse =
786         PythonPackage.newBuilder()
787             .setName(
788                 PythonPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PYTHON_PACKAGE]")
789                     .toString())
790             .setUri("uri116076")
791             .setPackageName("packageName908759025")
792             .setVersion("version351608024")
793             .setCreateTime(Timestamp.newBuilder().build())
794             .setUpdateTime(Timestamp.newBuilder().build())
795             .build();
796     mockService.addResponse(expectedResponse);
797 
798     PythonPackageName name =
799         PythonPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PYTHON_PACKAGE]");
800 
801     PythonPackage actualResponse = client.getPythonPackage(name);
802     Assert.assertEquals(expectedResponse, actualResponse);
803 
804     List<String> actualRequests = mockService.getRequestPaths();
805     Assert.assertEquals(1, actualRequests.size());
806 
807     String apiClientHeaderKey =
808         mockService
809             .getRequestHeaders()
810             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
811             .iterator()
812             .next();
813     Assert.assertTrue(
814         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
815             .matcher(apiClientHeaderKey)
816             .matches());
817   }
818 
819   @Test
getPythonPackageExceptionTest()820   public void getPythonPackageExceptionTest() throws Exception {
821     ApiException exception =
822         ApiExceptionFactory.createException(
823             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
824     mockService.addException(exception);
825 
826     try {
827       PythonPackageName name =
828           PythonPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PYTHON_PACKAGE]");
829       client.getPythonPackage(name);
830       Assert.fail("No exception raised");
831     } catch (InvalidArgumentException e) {
832       // Expected exception.
833     }
834   }
835 
836   @Test
getPythonPackageTest2()837   public void getPythonPackageTest2() throws Exception {
838     PythonPackage expectedResponse =
839         PythonPackage.newBuilder()
840             .setName(
841                 PythonPackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PYTHON_PACKAGE]")
842                     .toString())
843             .setUri("uri116076")
844             .setPackageName("packageName908759025")
845             .setVersion("version351608024")
846             .setCreateTime(Timestamp.newBuilder().build())
847             .setUpdateTime(Timestamp.newBuilder().build())
848             .build();
849     mockService.addResponse(expectedResponse);
850 
851     String name =
852         "projects/project-325/locations/location-325/repositories/repositorie-325/pythonPackages/pythonPackage-325";
853 
854     PythonPackage actualResponse = client.getPythonPackage(name);
855     Assert.assertEquals(expectedResponse, actualResponse);
856 
857     List<String> actualRequests = mockService.getRequestPaths();
858     Assert.assertEquals(1, actualRequests.size());
859 
860     String apiClientHeaderKey =
861         mockService
862             .getRequestHeaders()
863             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
864             .iterator()
865             .next();
866     Assert.assertTrue(
867         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
868             .matcher(apiClientHeaderKey)
869             .matches());
870   }
871 
872   @Test
getPythonPackageExceptionTest2()873   public void getPythonPackageExceptionTest2() throws Exception {
874     ApiException exception =
875         ApiExceptionFactory.createException(
876             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
877     mockService.addException(exception);
878 
879     try {
880       String name =
881           "projects/project-325/locations/location-325/repositories/repositorie-325/pythonPackages/pythonPackage-325";
882       client.getPythonPackage(name);
883       Assert.fail("No exception raised");
884     } catch (InvalidArgumentException e) {
885       // Expected exception.
886     }
887   }
888 
889   @Test
importAptArtifactsTest()890   public void importAptArtifactsTest() throws Exception {
891     ImportAptArtifactsResponse expectedResponse =
892         ImportAptArtifactsResponse.newBuilder()
893             .addAllAptArtifacts(new ArrayList<AptArtifact>())
894             .addAllErrors(new ArrayList<ImportAptArtifactsErrorInfo>())
895             .build();
896     Operation resultOperation =
897         Operation.newBuilder()
898             .setName("importAptArtifactsTest")
899             .setDone(true)
900             .setResponse(Any.pack(expectedResponse))
901             .build();
902     mockService.addResponse(resultOperation);
903 
904     ImportAptArtifactsRequest request =
905         ImportAptArtifactsRequest.newBuilder()
906             .setParent(
907                 "projects/project-9015/locations/location-9015/repositories/repositorie-9015")
908             .build();
909 
910     ImportAptArtifactsResponse actualResponse = client.importAptArtifactsAsync(request).get();
911     Assert.assertEquals(expectedResponse, actualResponse);
912 
913     List<String> actualRequests = mockService.getRequestPaths();
914     Assert.assertEquals(1, actualRequests.size());
915 
916     String apiClientHeaderKey =
917         mockService
918             .getRequestHeaders()
919             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
920             .iterator()
921             .next();
922     Assert.assertTrue(
923         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
924             .matcher(apiClientHeaderKey)
925             .matches());
926   }
927 
928   @Test
importAptArtifactsExceptionTest()929   public void importAptArtifactsExceptionTest() throws Exception {
930     ApiException exception =
931         ApiExceptionFactory.createException(
932             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
933     mockService.addException(exception);
934 
935     try {
936       ImportAptArtifactsRequest request =
937           ImportAptArtifactsRequest.newBuilder()
938               .setParent(
939                   "projects/project-9015/locations/location-9015/repositories/repositorie-9015")
940               .build();
941       client.importAptArtifactsAsync(request).get();
942       Assert.fail("No exception raised");
943     } catch (ExecutionException e) {
944     }
945   }
946 
947   @Test
importYumArtifactsTest()948   public void importYumArtifactsTest() throws Exception {
949     ImportYumArtifactsResponse expectedResponse =
950         ImportYumArtifactsResponse.newBuilder()
951             .addAllYumArtifacts(new ArrayList<YumArtifact>())
952             .addAllErrors(new ArrayList<ImportYumArtifactsErrorInfo>())
953             .build();
954     Operation resultOperation =
955         Operation.newBuilder()
956             .setName("importYumArtifactsTest")
957             .setDone(true)
958             .setResponse(Any.pack(expectedResponse))
959             .build();
960     mockService.addResponse(resultOperation);
961 
962     ImportYumArtifactsRequest request =
963         ImportYumArtifactsRequest.newBuilder()
964             .setParent(
965                 "projects/project-9015/locations/location-9015/repositories/repositorie-9015")
966             .build();
967 
968     ImportYumArtifactsResponse actualResponse = client.importYumArtifactsAsync(request).get();
969     Assert.assertEquals(expectedResponse, actualResponse);
970 
971     List<String> actualRequests = mockService.getRequestPaths();
972     Assert.assertEquals(1, actualRequests.size());
973 
974     String apiClientHeaderKey =
975         mockService
976             .getRequestHeaders()
977             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
978             .iterator()
979             .next();
980     Assert.assertTrue(
981         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
982             .matcher(apiClientHeaderKey)
983             .matches());
984   }
985 
986   @Test
importYumArtifactsExceptionTest()987   public void importYumArtifactsExceptionTest() throws Exception {
988     ApiException exception =
989         ApiExceptionFactory.createException(
990             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
991     mockService.addException(exception);
992 
993     try {
994       ImportYumArtifactsRequest request =
995           ImportYumArtifactsRequest.newBuilder()
996               .setParent(
997                   "projects/project-9015/locations/location-9015/repositories/repositorie-9015")
998               .build();
999       client.importYumArtifactsAsync(request).get();
1000       Assert.fail("No exception raised");
1001     } catch (ExecutionException e) {
1002     }
1003   }
1004 
1005   @Test
listRepositoriesTest()1006   public void listRepositoriesTest() throws Exception {
1007     Repository responsesElement = Repository.newBuilder().build();
1008     ListRepositoriesResponse expectedResponse =
1009         ListRepositoriesResponse.newBuilder()
1010             .setNextPageToken("")
1011             .addAllRepositories(Arrays.asList(responsesElement))
1012             .build();
1013     mockService.addResponse(expectedResponse);
1014 
1015     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1016 
1017     ListRepositoriesPagedResponse pagedListResponse = client.listRepositories(parent);
1018 
1019     List<Repository> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1020 
1021     Assert.assertEquals(1, resources.size());
1022     Assert.assertEquals(expectedResponse.getRepositoriesList().get(0), resources.get(0));
1023 
1024     List<String> actualRequests = mockService.getRequestPaths();
1025     Assert.assertEquals(1, actualRequests.size());
1026 
1027     String apiClientHeaderKey =
1028         mockService
1029             .getRequestHeaders()
1030             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1031             .iterator()
1032             .next();
1033     Assert.assertTrue(
1034         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1035             .matcher(apiClientHeaderKey)
1036             .matches());
1037   }
1038 
1039   @Test
listRepositoriesExceptionTest()1040   public void listRepositoriesExceptionTest() throws Exception {
1041     ApiException exception =
1042         ApiExceptionFactory.createException(
1043             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1044     mockService.addException(exception);
1045 
1046     try {
1047       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1048       client.listRepositories(parent);
1049       Assert.fail("No exception raised");
1050     } catch (InvalidArgumentException e) {
1051       // Expected exception.
1052     }
1053   }
1054 
1055   @Test
listRepositoriesTest2()1056   public void listRepositoriesTest2() throws Exception {
1057     Repository responsesElement = Repository.newBuilder().build();
1058     ListRepositoriesResponse expectedResponse =
1059         ListRepositoriesResponse.newBuilder()
1060             .setNextPageToken("")
1061             .addAllRepositories(Arrays.asList(responsesElement))
1062             .build();
1063     mockService.addResponse(expectedResponse);
1064 
1065     String parent = "projects/project-5833/locations/location-5833";
1066 
1067     ListRepositoriesPagedResponse pagedListResponse = client.listRepositories(parent);
1068 
1069     List<Repository> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1070 
1071     Assert.assertEquals(1, resources.size());
1072     Assert.assertEquals(expectedResponse.getRepositoriesList().get(0), resources.get(0));
1073 
1074     List<String> actualRequests = mockService.getRequestPaths();
1075     Assert.assertEquals(1, actualRequests.size());
1076 
1077     String apiClientHeaderKey =
1078         mockService
1079             .getRequestHeaders()
1080             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1081             .iterator()
1082             .next();
1083     Assert.assertTrue(
1084         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1085             .matcher(apiClientHeaderKey)
1086             .matches());
1087   }
1088 
1089   @Test
listRepositoriesExceptionTest2()1090   public void listRepositoriesExceptionTest2() throws Exception {
1091     ApiException exception =
1092         ApiExceptionFactory.createException(
1093             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1094     mockService.addException(exception);
1095 
1096     try {
1097       String parent = "projects/project-5833/locations/location-5833";
1098       client.listRepositories(parent);
1099       Assert.fail("No exception raised");
1100     } catch (InvalidArgumentException e) {
1101       // Expected exception.
1102     }
1103   }
1104 
1105   @Test
getRepositoryTest()1106   public void getRepositoryTest() throws Exception {
1107     Repository expectedResponse =
1108         Repository.newBuilder()
1109             .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1110             .setDescription("description-1724546052")
1111             .putAllLabels(new HashMap<String, String>())
1112             .setCreateTime(Timestamp.newBuilder().build())
1113             .setUpdateTime(Timestamp.newBuilder().build())
1114             .setKmsKeyName("kmsKeyName412586233")
1115             .build();
1116     mockService.addResponse(expectedResponse);
1117 
1118     RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1119 
1120     Repository actualResponse = client.getRepository(name);
1121     Assert.assertEquals(expectedResponse, actualResponse);
1122 
1123     List<String> actualRequests = mockService.getRequestPaths();
1124     Assert.assertEquals(1, actualRequests.size());
1125 
1126     String apiClientHeaderKey =
1127         mockService
1128             .getRequestHeaders()
1129             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1130             .iterator()
1131             .next();
1132     Assert.assertTrue(
1133         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1134             .matcher(apiClientHeaderKey)
1135             .matches());
1136   }
1137 
1138   @Test
getRepositoryExceptionTest()1139   public void getRepositoryExceptionTest() throws Exception {
1140     ApiException exception =
1141         ApiExceptionFactory.createException(
1142             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1143     mockService.addException(exception);
1144 
1145     try {
1146       RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1147       client.getRepository(name);
1148       Assert.fail("No exception raised");
1149     } catch (InvalidArgumentException e) {
1150       // Expected exception.
1151     }
1152   }
1153 
1154   @Test
getRepositoryTest2()1155   public void getRepositoryTest2() throws Exception {
1156     Repository expectedResponse =
1157         Repository.newBuilder()
1158             .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1159             .setDescription("description-1724546052")
1160             .putAllLabels(new HashMap<String, String>())
1161             .setCreateTime(Timestamp.newBuilder().build())
1162             .setUpdateTime(Timestamp.newBuilder().build())
1163             .setKmsKeyName("kmsKeyName412586233")
1164             .build();
1165     mockService.addResponse(expectedResponse);
1166 
1167     String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840";
1168 
1169     Repository actualResponse = client.getRepository(name);
1170     Assert.assertEquals(expectedResponse, actualResponse);
1171 
1172     List<String> actualRequests = mockService.getRequestPaths();
1173     Assert.assertEquals(1, actualRequests.size());
1174 
1175     String apiClientHeaderKey =
1176         mockService
1177             .getRequestHeaders()
1178             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1179             .iterator()
1180             .next();
1181     Assert.assertTrue(
1182         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1183             .matcher(apiClientHeaderKey)
1184             .matches());
1185   }
1186 
1187   @Test
getRepositoryExceptionTest2()1188   public void getRepositoryExceptionTest2() throws Exception {
1189     ApiException exception =
1190         ApiExceptionFactory.createException(
1191             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1192     mockService.addException(exception);
1193 
1194     try {
1195       String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840";
1196       client.getRepository(name);
1197       Assert.fail("No exception raised");
1198     } catch (InvalidArgumentException e) {
1199       // Expected exception.
1200     }
1201   }
1202 
1203   @Test
createRepositoryTest()1204   public void createRepositoryTest() throws Exception {
1205     Repository expectedResponse =
1206         Repository.newBuilder()
1207             .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1208             .setDescription("description-1724546052")
1209             .putAllLabels(new HashMap<String, String>())
1210             .setCreateTime(Timestamp.newBuilder().build())
1211             .setUpdateTime(Timestamp.newBuilder().build())
1212             .setKmsKeyName("kmsKeyName412586233")
1213             .build();
1214     Operation resultOperation =
1215         Operation.newBuilder()
1216             .setName("createRepositoryTest")
1217             .setDone(true)
1218             .setResponse(Any.pack(expectedResponse))
1219             .build();
1220     mockService.addResponse(resultOperation);
1221 
1222     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1223     Repository repository = Repository.newBuilder().build();
1224     String repositoryId = "repositoryId2113747461";
1225 
1226     Repository actualResponse =
1227         client.createRepositoryAsync(parent, repository, repositoryId).get();
1228     Assert.assertEquals(expectedResponse, actualResponse);
1229 
1230     List<String> actualRequests = mockService.getRequestPaths();
1231     Assert.assertEquals(1, actualRequests.size());
1232 
1233     String apiClientHeaderKey =
1234         mockService
1235             .getRequestHeaders()
1236             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1237             .iterator()
1238             .next();
1239     Assert.assertTrue(
1240         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1241             .matcher(apiClientHeaderKey)
1242             .matches());
1243   }
1244 
1245   @Test
createRepositoryExceptionTest()1246   public void createRepositoryExceptionTest() throws Exception {
1247     ApiException exception =
1248         ApiExceptionFactory.createException(
1249             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1250     mockService.addException(exception);
1251 
1252     try {
1253       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1254       Repository repository = Repository.newBuilder().build();
1255       String repositoryId = "repositoryId2113747461";
1256       client.createRepositoryAsync(parent, repository, repositoryId).get();
1257       Assert.fail("No exception raised");
1258     } catch (ExecutionException e) {
1259     }
1260   }
1261 
1262   @Test
createRepositoryTest2()1263   public void createRepositoryTest2() throws Exception {
1264     Repository expectedResponse =
1265         Repository.newBuilder()
1266             .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1267             .setDescription("description-1724546052")
1268             .putAllLabels(new HashMap<String, String>())
1269             .setCreateTime(Timestamp.newBuilder().build())
1270             .setUpdateTime(Timestamp.newBuilder().build())
1271             .setKmsKeyName("kmsKeyName412586233")
1272             .build();
1273     Operation resultOperation =
1274         Operation.newBuilder()
1275             .setName("createRepositoryTest")
1276             .setDone(true)
1277             .setResponse(Any.pack(expectedResponse))
1278             .build();
1279     mockService.addResponse(resultOperation);
1280 
1281     String parent = "projects/project-5833/locations/location-5833";
1282     Repository repository = Repository.newBuilder().build();
1283     String repositoryId = "repositoryId2113747461";
1284 
1285     Repository actualResponse =
1286         client.createRepositoryAsync(parent, repository, repositoryId).get();
1287     Assert.assertEquals(expectedResponse, actualResponse);
1288 
1289     List<String> actualRequests = mockService.getRequestPaths();
1290     Assert.assertEquals(1, actualRequests.size());
1291 
1292     String apiClientHeaderKey =
1293         mockService
1294             .getRequestHeaders()
1295             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1296             .iterator()
1297             .next();
1298     Assert.assertTrue(
1299         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1300             .matcher(apiClientHeaderKey)
1301             .matches());
1302   }
1303 
1304   @Test
createRepositoryExceptionTest2()1305   public void createRepositoryExceptionTest2() throws Exception {
1306     ApiException exception =
1307         ApiExceptionFactory.createException(
1308             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1309     mockService.addException(exception);
1310 
1311     try {
1312       String parent = "projects/project-5833/locations/location-5833";
1313       Repository repository = Repository.newBuilder().build();
1314       String repositoryId = "repositoryId2113747461";
1315       client.createRepositoryAsync(parent, repository, repositoryId).get();
1316       Assert.fail("No exception raised");
1317     } catch (ExecutionException e) {
1318     }
1319   }
1320 
1321   @Test
updateRepositoryTest()1322   public void updateRepositoryTest() throws Exception {
1323     Repository expectedResponse =
1324         Repository.newBuilder()
1325             .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1326             .setDescription("description-1724546052")
1327             .putAllLabels(new HashMap<String, String>())
1328             .setCreateTime(Timestamp.newBuilder().build())
1329             .setUpdateTime(Timestamp.newBuilder().build())
1330             .setKmsKeyName("kmsKeyName412586233")
1331             .build();
1332     mockService.addResponse(expectedResponse);
1333 
1334     Repository repository =
1335         Repository.newBuilder()
1336             .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1337             .setDescription("description-1724546052")
1338             .putAllLabels(new HashMap<String, String>())
1339             .setCreateTime(Timestamp.newBuilder().build())
1340             .setUpdateTime(Timestamp.newBuilder().build())
1341             .setKmsKeyName("kmsKeyName412586233")
1342             .build();
1343     FieldMask updateMask = FieldMask.newBuilder().build();
1344 
1345     Repository actualResponse = client.updateRepository(repository, updateMask);
1346     Assert.assertEquals(expectedResponse, actualResponse);
1347 
1348     List<String> actualRequests = mockService.getRequestPaths();
1349     Assert.assertEquals(1, actualRequests.size());
1350 
1351     String apiClientHeaderKey =
1352         mockService
1353             .getRequestHeaders()
1354             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1355             .iterator()
1356             .next();
1357     Assert.assertTrue(
1358         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1359             .matcher(apiClientHeaderKey)
1360             .matches());
1361   }
1362 
1363   @Test
updateRepositoryExceptionTest()1364   public void updateRepositoryExceptionTest() throws Exception {
1365     ApiException exception =
1366         ApiExceptionFactory.createException(
1367             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1368     mockService.addException(exception);
1369 
1370     try {
1371       Repository repository =
1372           Repository.newBuilder()
1373               .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
1374               .setDescription("description-1724546052")
1375               .putAllLabels(new HashMap<String, String>())
1376               .setCreateTime(Timestamp.newBuilder().build())
1377               .setUpdateTime(Timestamp.newBuilder().build())
1378               .setKmsKeyName("kmsKeyName412586233")
1379               .build();
1380       FieldMask updateMask = FieldMask.newBuilder().build();
1381       client.updateRepository(repository, updateMask);
1382       Assert.fail("No exception raised");
1383     } catch (InvalidArgumentException e) {
1384       // Expected exception.
1385     }
1386   }
1387 
1388   @Test
deleteRepositoryTest()1389   public void deleteRepositoryTest() throws Exception {
1390     Empty expectedResponse = Empty.newBuilder().build();
1391     Operation resultOperation =
1392         Operation.newBuilder()
1393             .setName("deleteRepositoryTest")
1394             .setDone(true)
1395             .setResponse(Any.pack(expectedResponse))
1396             .build();
1397     mockService.addResponse(resultOperation);
1398 
1399     RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1400 
1401     client.deleteRepositoryAsync(name).get();
1402 
1403     List<String> actualRequests = mockService.getRequestPaths();
1404     Assert.assertEquals(1, actualRequests.size());
1405 
1406     String apiClientHeaderKey =
1407         mockService
1408             .getRequestHeaders()
1409             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1410             .iterator()
1411             .next();
1412     Assert.assertTrue(
1413         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1414             .matcher(apiClientHeaderKey)
1415             .matches());
1416   }
1417 
1418   @Test
deleteRepositoryExceptionTest()1419   public void deleteRepositoryExceptionTest() throws Exception {
1420     ApiException exception =
1421         ApiExceptionFactory.createException(
1422             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1423     mockService.addException(exception);
1424 
1425     try {
1426       RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1427       client.deleteRepositoryAsync(name).get();
1428       Assert.fail("No exception raised");
1429     } catch (ExecutionException e) {
1430     }
1431   }
1432 
1433   @Test
deleteRepositoryTest2()1434   public void deleteRepositoryTest2() throws Exception {
1435     Empty expectedResponse = Empty.newBuilder().build();
1436     Operation resultOperation =
1437         Operation.newBuilder()
1438             .setName("deleteRepositoryTest")
1439             .setDone(true)
1440             .setResponse(Any.pack(expectedResponse))
1441             .build();
1442     mockService.addResponse(resultOperation);
1443 
1444     String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840";
1445 
1446     client.deleteRepositoryAsync(name).get();
1447 
1448     List<String> actualRequests = mockService.getRequestPaths();
1449     Assert.assertEquals(1, actualRequests.size());
1450 
1451     String apiClientHeaderKey =
1452         mockService
1453             .getRequestHeaders()
1454             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1455             .iterator()
1456             .next();
1457     Assert.assertTrue(
1458         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1459             .matcher(apiClientHeaderKey)
1460             .matches());
1461   }
1462 
1463   @Test
deleteRepositoryExceptionTest2()1464   public void deleteRepositoryExceptionTest2() throws Exception {
1465     ApiException exception =
1466         ApiExceptionFactory.createException(
1467             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1468     mockService.addException(exception);
1469 
1470     try {
1471       String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840";
1472       client.deleteRepositoryAsync(name).get();
1473       Assert.fail("No exception raised");
1474     } catch (ExecutionException e) {
1475     }
1476   }
1477 
1478   @Test
listPackagesTest()1479   public void listPackagesTest() throws Exception {
1480     Package responsesElement = Package.newBuilder().build();
1481     ListPackagesResponse expectedResponse =
1482         ListPackagesResponse.newBuilder()
1483             .setNextPageToken("")
1484             .addAllPackages(Arrays.asList(responsesElement))
1485             .build();
1486     mockService.addResponse(expectedResponse);
1487 
1488     RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1489 
1490     ListPackagesPagedResponse pagedListResponse = client.listPackages(parent);
1491 
1492     List<Package> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1493 
1494     Assert.assertEquals(1, resources.size());
1495     Assert.assertEquals(expectedResponse.getPackagesList().get(0), resources.get(0));
1496 
1497     List<String> actualRequests = mockService.getRequestPaths();
1498     Assert.assertEquals(1, actualRequests.size());
1499 
1500     String apiClientHeaderKey =
1501         mockService
1502             .getRequestHeaders()
1503             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1504             .iterator()
1505             .next();
1506     Assert.assertTrue(
1507         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1508             .matcher(apiClientHeaderKey)
1509             .matches());
1510   }
1511 
1512   @Test
listPackagesExceptionTest()1513   public void listPackagesExceptionTest() throws Exception {
1514     ApiException exception =
1515         ApiExceptionFactory.createException(
1516             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1517     mockService.addException(exception);
1518 
1519     try {
1520       RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1521       client.listPackages(parent);
1522       Assert.fail("No exception raised");
1523     } catch (InvalidArgumentException e) {
1524       // Expected exception.
1525     }
1526   }
1527 
1528   @Test
listPackagesTest2()1529   public void listPackagesTest2() throws Exception {
1530     Package responsesElement = Package.newBuilder().build();
1531     ListPackagesResponse expectedResponse =
1532         ListPackagesResponse.newBuilder()
1533             .setNextPageToken("")
1534             .addAllPackages(Arrays.asList(responsesElement))
1535             .build();
1536     mockService.addResponse(expectedResponse);
1537 
1538     String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
1539 
1540     ListPackagesPagedResponse pagedListResponse = client.listPackages(parent);
1541 
1542     List<Package> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1543 
1544     Assert.assertEquals(1, resources.size());
1545     Assert.assertEquals(expectedResponse.getPackagesList().get(0), resources.get(0));
1546 
1547     List<String> actualRequests = mockService.getRequestPaths();
1548     Assert.assertEquals(1, actualRequests.size());
1549 
1550     String apiClientHeaderKey =
1551         mockService
1552             .getRequestHeaders()
1553             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1554             .iterator()
1555             .next();
1556     Assert.assertTrue(
1557         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1558             .matcher(apiClientHeaderKey)
1559             .matches());
1560   }
1561 
1562   @Test
listPackagesExceptionTest2()1563   public void listPackagesExceptionTest2() throws Exception {
1564     ApiException exception =
1565         ApiExceptionFactory.createException(
1566             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1567     mockService.addException(exception);
1568 
1569     try {
1570       String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
1571       client.listPackages(parent);
1572       Assert.fail("No exception raised");
1573     } catch (InvalidArgumentException e) {
1574       // Expected exception.
1575     }
1576   }
1577 
1578   @Test
getPackageTest()1579   public void getPackageTest() throws Exception {
1580     Package expectedResponse =
1581         Package.newBuilder()
1582             .setName(
1583                 PackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PACKAGE]").toString())
1584             .setDisplayName("displayName1714148973")
1585             .setCreateTime(Timestamp.newBuilder().build())
1586             .setUpdateTime(Timestamp.newBuilder().build())
1587             .build();
1588     mockService.addResponse(expectedResponse);
1589 
1590     PackageName name = PackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PACKAGE]");
1591 
1592     Package actualResponse = client.getPackage(name);
1593     Assert.assertEquals(expectedResponse, actualResponse);
1594 
1595     List<String> actualRequests = mockService.getRequestPaths();
1596     Assert.assertEquals(1, actualRequests.size());
1597 
1598     String apiClientHeaderKey =
1599         mockService
1600             .getRequestHeaders()
1601             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1602             .iterator()
1603             .next();
1604     Assert.assertTrue(
1605         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1606             .matcher(apiClientHeaderKey)
1607             .matches());
1608   }
1609 
1610   @Test
getPackageExceptionTest()1611   public void getPackageExceptionTest() throws Exception {
1612     ApiException exception =
1613         ApiExceptionFactory.createException(
1614             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1615     mockService.addException(exception);
1616 
1617     try {
1618       PackageName name = PackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PACKAGE]");
1619       client.getPackage(name);
1620       Assert.fail("No exception raised");
1621     } catch (InvalidArgumentException e) {
1622       // Expected exception.
1623     }
1624   }
1625 
1626   @Test
getPackageTest2()1627   public void getPackageTest2() throws Exception {
1628     Package expectedResponse =
1629         Package.newBuilder()
1630             .setName(
1631                 PackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PACKAGE]").toString())
1632             .setDisplayName("displayName1714148973")
1633             .setCreateTime(Timestamp.newBuilder().build())
1634             .setUpdateTime(Timestamp.newBuilder().build())
1635             .build();
1636     mockService.addResponse(expectedResponse);
1637 
1638     String name =
1639         "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639";
1640 
1641     Package actualResponse = client.getPackage(name);
1642     Assert.assertEquals(expectedResponse, actualResponse);
1643 
1644     List<String> actualRequests = mockService.getRequestPaths();
1645     Assert.assertEquals(1, actualRequests.size());
1646 
1647     String apiClientHeaderKey =
1648         mockService
1649             .getRequestHeaders()
1650             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1651             .iterator()
1652             .next();
1653     Assert.assertTrue(
1654         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1655             .matcher(apiClientHeaderKey)
1656             .matches());
1657   }
1658 
1659   @Test
getPackageExceptionTest2()1660   public void getPackageExceptionTest2() throws Exception {
1661     ApiException exception =
1662         ApiExceptionFactory.createException(
1663             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1664     mockService.addException(exception);
1665 
1666     try {
1667       String name =
1668           "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639";
1669       client.getPackage(name);
1670       Assert.fail("No exception raised");
1671     } catch (InvalidArgumentException e) {
1672       // Expected exception.
1673     }
1674   }
1675 
1676   @Test
deletePackageTest()1677   public void deletePackageTest() throws Exception {
1678     Empty expectedResponse = Empty.newBuilder().build();
1679     Operation resultOperation =
1680         Operation.newBuilder()
1681             .setName("deletePackageTest")
1682             .setDone(true)
1683             .setResponse(Any.pack(expectedResponse))
1684             .build();
1685     mockService.addResponse(resultOperation);
1686 
1687     PackageName name = PackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PACKAGE]");
1688 
1689     client.deletePackageAsync(name).get();
1690 
1691     List<String> actualRequests = mockService.getRequestPaths();
1692     Assert.assertEquals(1, actualRequests.size());
1693 
1694     String apiClientHeaderKey =
1695         mockService
1696             .getRequestHeaders()
1697             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1698             .iterator()
1699             .next();
1700     Assert.assertTrue(
1701         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1702             .matcher(apiClientHeaderKey)
1703             .matches());
1704   }
1705 
1706   @Test
deletePackageExceptionTest()1707   public void deletePackageExceptionTest() throws Exception {
1708     ApiException exception =
1709         ApiExceptionFactory.createException(
1710             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1711     mockService.addException(exception);
1712 
1713     try {
1714       PackageName name = PackageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[PACKAGE]");
1715       client.deletePackageAsync(name).get();
1716       Assert.fail("No exception raised");
1717     } catch (ExecutionException e) {
1718     }
1719   }
1720 
1721   @Test
deletePackageTest2()1722   public void deletePackageTest2() throws Exception {
1723     Empty expectedResponse = Empty.newBuilder().build();
1724     Operation resultOperation =
1725         Operation.newBuilder()
1726             .setName("deletePackageTest")
1727             .setDone(true)
1728             .setResponse(Any.pack(expectedResponse))
1729             .build();
1730     mockService.addResponse(resultOperation);
1731 
1732     String name =
1733         "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639";
1734 
1735     client.deletePackageAsync(name).get();
1736 
1737     List<String> actualRequests = mockService.getRequestPaths();
1738     Assert.assertEquals(1, actualRequests.size());
1739 
1740     String apiClientHeaderKey =
1741         mockService
1742             .getRequestHeaders()
1743             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1744             .iterator()
1745             .next();
1746     Assert.assertTrue(
1747         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1748             .matcher(apiClientHeaderKey)
1749             .matches());
1750   }
1751 
1752   @Test
deletePackageExceptionTest2()1753   public void deletePackageExceptionTest2() throws Exception {
1754     ApiException exception =
1755         ApiExceptionFactory.createException(
1756             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1757     mockService.addException(exception);
1758 
1759     try {
1760       String name =
1761           "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639";
1762       client.deletePackageAsync(name).get();
1763       Assert.fail("No exception raised");
1764     } catch (ExecutionException e) {
1765     }
1766   }
1767 
1768   @Test
listVersionsTest()1769   public void listVersionsTest() throws Exception {
1770     Version responsesElement = Version.newBuilder().build();
1771     ListVersionsResponse expectedResponse =
1772         ListVersionsResponse.newBuilder()
1773             .setNextPageToken("")
1774             .addAllVersions(Arrays.asList(responsesElement))
1775             .build();
1776     mockService.addResponse(expectedResponse);
1777 
1778     String parent =
1779         "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394";
1780 
1781     ListVersionsPagedResponse pagedListResponse = client.listVersions(parent);
1782 
1783     List<Version> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1784 
1785     Assert.assertEquals(1, resources.size());
1786     Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0));
1787 
1788     List<String> actualRequests = mockService.getRequestPaths();
1789     Assert.assertEquals(1, actualRequests.size());
1790 
1791     String apiClientHeaderKey =
1792         mockService
1793             .getRequestHeaders()
1794             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1795             .iterator()
1796             .next();
1797     Assert.assertTrue(
1798         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1799             .matcher(apiClientHeaderKey)
1800             .matches());
1801   }
1802 
1803   @Test
listVersionsExceptionTest()1804   public void listVersionsExceptionTest() throws Exception {
1805     ApiException exception =
1806         ApiExceptionFactory.createException(
1807             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1808     mockService.addException(exception);
1809 
1810     try {
1811       String parent =
1812           "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394";
1813       client.listVersions(parent);
1814       Assert.fail("No exception raised");
1815     } catch (InvalidArgumentException e) {
1816       // Expected exception.
1817     }
1818   }
1819 
1820   @Test
getVersionTest()1821   public void getVersionTest() throws Exception {
1822     Version expectedResponse =
1823         Version.newBuilder()
1824             .setName("name3373707")
1825             .setDescription("description-1724546052")
1826             .setCreateTime(Timestamp.newBuilder().build())
1827             .setUpdateTime(Timestamp.newBuilder().build())
1828             .addAllRelatedTags(new ArrayList<Tag>())
1829             .setMetadata(Struct.newBuilder().build())
1830             .build();
1831     mockService.addResponse(expectedResponse);
1832 
1833     String name =
1834         "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642";
1835 
1836     Version actualResponse = client.getVersion(name);
1837     Assert.assertEquals(expectedResponse, actualResponse);
1838 
1839     List<String> actualRequests = mockService.getRequestPaths();
1840     Assert.assertEquals(1, actualRequests.size());
1841 
1842     String apiClientHeaderKey =
1843         mockService
1844             .getRequestHeaders()
1845             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1846             .iterator()
1847             .next();
1848     Assert.assertTrue(
1849         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1850             .matcher(apiClientHeaderKey)
1851             .matches());
1852   }
1853 
1854   @Test
getVersionExceptionTest()1855   public void getVersionExceptionTest() throws Exception {
1856     ApiException exception =
1857         ApiExceptionFactory.createException(
1858             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1859     mockService.addException(exception);
1860 
1861     try {
1862       String name =
1863           "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642";
1864       client.getVersion(name);
1865       Assert.fail("No exception raised");
1866     } catch (InvalidArgumentException e) {
1867       // Expected exception.
1868     }
1869   }
1870 
1871   @Test
deleteVersionTest()1872   public void deleteVersionTest() throws Exception {
1873     Empty expectedResponse = Empty.newBuilder().build();
1874     Operation resultOperation =
1875         Operation.newBuilder()
1876             .setName("deleteVersionTest")
1877             .setDone(true)
1878             .setResponse(Any.pack(expectedResponse))
1879             .build();
1880     mockService.addResponse(resultOperation);
1881 
1882     String name =
1883         "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642";
1884 
1885     client.deleteVersionAsync(name).get();
1886 
1887     List<String> actualRequests = mockService.getRequestPaths();
1888     Assert.assertEquals(1, actualRequests.size());
1889 
1890     String apiClientHeaderKey =
1891         mockService
1892             .getRequestHeaders()
1893             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1894             .iterator()
1895             .next();
1896     Assert.assertTrue(
1897         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1898             .matcher(apiClientHeaderKey)
1899             .matches());
1900   }
1901 
1902   @Test
deleteVersionExceptionTest()1903   public void deleteVersionExceptionTest() throws Exception {
1904     ApiException exception =
1905         ApiExceptionFactory.createException(
1906             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1907     mockService.addException(exception);
1908 
1909     try {
1910       String name =
1911           "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642";
1912       client.deleteVersionAsync(name).get();
1913       Assert.fail("No exception raised");
1914     } catch (ExecutionException e) {
1915     }
1916   }
1917 
1918   @Test
listFilesTest()1919   public void listFilesTest() throws Exception {
1920     File responsesElement = File.newBuilder().build();
1921     ListFilesResponse expectedResponse =
1922         ListFilesResponse.newBuilder()
1923             .setNextPageToken("")
1924             .addAllFiles(Arrays.asList(responsesElement))
1925             .build();
1926     mockService.addResponse(expectedResponse);
1927 
1928     RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1929 
1930     ListFilesPagedResponse pagedListResponse = client.listFiles(parent);
1931 
1932     List<File> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1933 
1934     Assert.assertEquals(1, resources.size());
1935     Assert.assertEquals(expectedResponse.getFilesList().get(0), resources.get(0));
1936 
1937     List<String> actualRequests = mockService.getRequestPaths();
1938     Assert.assertEquals(1, actualRequests.size());
1939 
1940     String apiClientHeaderKey =
1941         mockService
1942             .getRequestHeaders()
1943             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1944             .iterator()
1945             .next();
1946     Assert.assertTrue(
1947         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1948             .matcher(apiClientHeaderKey)
1949             .matches());
1950   }
1951 
1952   @Test
listFilesExceptionTest()1953   public void listFilesExceptionTest() throws Exception {
1954     ApiException exception =
1955         ApiExceptionFactory.createException(
1956             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1957     mockService.addException(exception);
1958 
1959     try {
1960       RepositoryName parent = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
1961       client.listFiles(parent);
1962       Assert.fail("No exception raised");
1963     } catch (InvalidArgumentException e) {
1964       // Expected exception.
1965     }
1966   }
1967 
1968   @Test
listFilesTest2()1969   public void listFilesTest2() throws Exception {
1970     File responsesElement = File.newBuilder().build();
1971     ListFilesResponse expectedResponse =
1972         ListFilesResponse.newBuilder()
1973             .setNextPageToken("")
1974             .addAllFiles(Arrays.asList(responsesElement))
1975             .build();
1976     mockService.addResponse(expectedResponse);
1977 
1978     String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
1979 
1980     ListFilesPagedResponse pagedListResponse = client.listFiles(parent);
1981 
1982     List<File> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1983 
1984     Assert.assertEquals(1, resources.size());
1985     Assert.assertEquals(expectedResponse.getFilesList().get(0), resources.get(0));
1986 
1987     List<String> actualRequests = mockService.getRequestPaths();
1988     Assert.assertEquals(1, actualRequests.size());
1989 
1990     String apiClientHeaderKey =
1991         mockService
1992             .getRequestHeaders()
1993             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1994             .iterator()
1995             .next();
1996     Assert.assertTrue(
1997         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1998             .matcher(apiClientHeaderKey)
1999             .matches());
2000   }
2001 
2002   @Test
listFilesExceptionTest2()2003   public void listFilesExceptionTest2() throws Exception {
2004     ApiException exception =
2005         ApiExceptionFactory.createException(
2006             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2007     mockService.addException(exception);
2008 
2009     try {
2010       String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015";
2011       client.listFiles(parent);
2012       Assert.fail("No exception raised");
2013     } catch (InvalidArgumentException e) {
2014       // Expected exception.
2015     }
2016   }
2017 
2018   @Test
getFileTest()2019   public void getFileTest() throws Exception {
2020     File expectedResponse =
2021         File.newBuilder()
2022             .setName(FileName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[FILE]").toString())
2023             .setSizeBytes(-1796325715)
2024             .addAllHashes(new ArrayList<Hash>())
2025             .setCreateTime(Timestamp.newBuilder().build())
2026             .setUpdateTime(Timestamp.newBuilder().build())
2027             .setOwner("owner106164915")
2028             .setFetchTime(Timestamp.newBuilder().build())
2029             .build();
2030     mockService.addResponse(expectedResponse);
2031 
2032     FileName name = FileName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[FILE]");
2033 
2034     File actualResponse = client.getFile(name);
2035     Assert.assertEquals(expectedResponse, actualResponse);
2036 
2037     List<String> actualRequests = mockService.getRequestPaths();
2038     Assert.assertEquals(1, actualRequests.size());
2039 
2040     String apiClientHeaderKey =
2041         mockService
2042             .getRequestHeaders()
2043             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2044             .iterator()
2045             .next();
2046     Assert.assertTrue(
2047         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2048             .matcher(apiClientHeaderKey)
2049             .matches());
2050   }
2051 
2052   @Test
getFileExceptionTest()2053   public void getFileExceptionTest() throws Exception {
2054     ApiException exception =
2055         ApiExceptionFactory.createException(
2056             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2057     mockService.addException(exception);
2058 
2059     try {
2060       FileName name = FileName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[FILE]");
2061       client.getFile(name);
2062       Assert.fail("No exception raised");
2063     } catch (InvalidArgumentException e) {
2064       // Expected exception.
2065     }
2066   }
2067 
2068   @Test
getFileTest2()2069   public void getFileTest2() throws Exception {
2070     File expectedResponse =
2071         File.newBuilder()
2072             .setName(FileName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[FILE]").toString())
2073             .setSizeBytes(-1796325715)
2074             .addAllHashes(new ArrayList<Hash>())
2075             .setCreateTime(Timestamp.newBuilder().build())
2076             .setUpdateTime(Timestamp.newBuilder().build())
2077             .setOwner("owner106164915")
2078             .setFetchTime(Timestamp.newBuilder().build())
2079             .build();
2080     mockService.addResponse(expectedResponse);
2081 
2082     String name =
2083         "projects/project-3631/locations/location-3631/repositories/repositorie-3631/files/file-3631";
2084 
2085     File actualResponse = client.getFile(name);
2086     Assert.assertEquals(expectedResponse, actualResponse);
2087 
2088     List<String> actualRequests = mockService.getRequestPaths();
2089     Assert.assertEquals(1, actualRequests.size());
2090 
2091     String apiClientHeaderKey =
2092         mockService
2093             .getRequestHeaders()
2094             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2095             .iterator()
2096             .next();
2097     Assert.assertTrue(
2098         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2099             .matcher(apiClientHeaderKey)
2100             .matches());
2101   }
2102 
2103   @Test
getFileExceptionTest2()2104   public void getFileExceptionTest2() throws Exception {
2105     ApiException exception =
2106         ApiExceptionFactory.createException(
2107             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2108     mockService.addException(exception);
2109 
2110     try {
2111       String name =
2112           "projects/project-3631/locations/location-3631/repositories/repositorie-3631/files/file-3631";
2113       client.getFile(name);
2114       Assert.fail("No exception raised");
2115     } catch (InvalidArgumentException e) {
2116       // Expected exception.
2117     }
2118   }
2119 
2120   @Test
listTagsTest()2121   public void listTagsTest() throws Exception {
2122     Tag responsesElement = Tag.newBuilder().build();
2123     ListTagsResponse expectedResponse =
2124         ListTagsResponse.newBuilder()
2125             .setNextPageToken("")
2126             .addAllTags(Arrays.asList(responsesElement))
2127             .build();
2128     mockService.addResponse(expectedResponse);
2129 
2130     String parent =
2131         "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394";
2132 
2133     ListTagsPagedResponse pagedListResponse = client.listTags(parent);
2134 
2135     List<Tag> resources = Lists.newArrayList(pagedListResponse.iterateAll());
2136 
2137     Assert.assertEquals(1, resources.size());
2138     Assert.assertEquals(expectedResponse.getTagsList().get(0), resources.get(0));
2139 
2140     List<String> actualRequests = mockService.getRequestPaths();
2141     Assert.assertEquals(1, actualRequests.size());
2142 
2143     String apiClientHeaderKey =
2144         mockService
2145             .getRequestHeaders()
2146             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2147             .iterator()
2148             .next();
2149     Assert.assertTrue(
2150         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2151             .matcher(apiClientHeaderKey)
2152             .matches());
2153   }
2154 
2155   @Test
listTagsExceptionTest()2156   public void listTagsExceptionTest() throws Exception {
2157     ApiException exception =
2158         ApiExceptionFactory.createException(
2159             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2160     mockService.addException(exception);
2161 
2162     try {
2163       String parent =
2164           "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394";
2165       client.listTags(parent);
2166       Assert.fail("No exception raised");
2167     } catch (InvalidArgumentException e) {
2168       // Expected exception.
2169     }
2170   }
2171 
2172   @Test
getTagTest()2173   public void getTagTest() throws Exception {
2174     Tag expectedResponse =
2175         Tag.newBuilder().setName("name3373707").setVersion("version351608024").build();
2176     mockService.addResponse(expectedResponse);
2177 
2178     String name =
2179         "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748";
2180 
2181     Tag actualResponse = client.getTag(name);
2182     Assert.assertEquals(expectedResponse, actualResponse);
2183 
2184     List<String> actualRequests = mockService.getRequestPaths();
2185     Assert.assertEquals(1, actualRequests.size());
2186 
2187     String apiClientHeaderKey =
2188         mockService
2189             .getRequestHeaders()
2190             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2191             .iterator()
2192             .next();
2193     Assert.assertTrue(
2194         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2195             .matcher(apiClientHeaderKey)
2196             .matches());
2197   }
2198 
2199   @Test
getTagExceptionTest()2200   public void getTagExceptionTest() throws Exception {
2201     ApiException exception =
2202         ApiExceptionFactory.createException(
2203             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2204     mockService.addException(exception);
2205 
2206     try {
2207       String name =
2208           "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748";
2209       client.getTag(name);
2210       Assert.fail("No exception raised");
2211     } catch (InvalidArgumentException e) {
2212       // Expected exception.
2213     }
2214   }
2215 
2216   @Test
createTagTest()2217   public void createTagTest() throws Exception {
2218     Tag expectedResponse =
2219         Tag.newBuilder().setName("name3373707").setVersion("version351608024").build();
2220     mockService.addResponse(expectedResponse);
2221 
2222     String parent =
2223         "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394";
2224     Tag tag = Tag.newBuilder().build();
2225     String tagId = "tagId110119509";
2226 
2227     Tag actualResponse = client.createTag(parent, tag, tagId);
2228     Assert.assertEquals(expectedResponse, actualResponse);
2229 
2230     List<String> actualRequests = mockService.getRequestPaths();
2231     Assert.assertEquals(1, actualRequests.size());
2232 
2233     String apiClientHeaderKey =
2234         mockService
2235             .getRequestHeaders()
2236             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2237             .iterator()
2238             .next();
2239     Assert.assertTrue(
2240         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2241             .matcher(apiClientHeaderKey)
2242             .matches());
2243   }
2244 
2245   @Test
createTagExceptionTest()2246   public void createTagExceptionTest() throws Exception {
2247     ApiException exception =
2248         ApiExceptionFactory.createException(
2249             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2250     mockService.addException(exception);
2251 
2252     try {
2253       String parent =
2254           "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394";
2255       Tag tag = Tag.newBuilder().build();
2256       String tagId = "tagId110119509";
2257       client.createTag(parent, tag, tagId);
2258       Assert.fail("No exception raised");
2259     } catch (InvalidArgumentException e) {
2260       // Expected exception.
2261     }
2262   }
2263 
2264   @Test
updateTagTest()2265   public void updateTagTest() throws Exception {
2266     Tag expectedResponse =
2267         Tag.newBuilder().setName("name3373707").setVersion("version351608024").build();
2268     mockService.addResponse(expectedResponse);
2269 
2270     Tag tag =
2271         Tag.newBuilder()
2272             .setName(
2273                 "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748")
2274             .setVersion("version351608024")
2275             .build();
2276     FieldMask updateMask = FieldMask.newBuilder().build();
2277 
2278     Tag actualResponse = client.updateTag(tag, updateMask);
2279     Assert.assertEquals(expectedResponse, actualResponse);
2280 
2281     List<String> actualRequests = mockService.getRequestPaths();
2282     Assert.assertEquals(1, actualRequests.size());
2283 
2284     String apiClientHeaderKey =
2285         mockService
2286             .getRequestHeaders()
2287             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2288             .iterator()
2289             .next();
2290     Assert.assertTrue(
2291         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2292             .matcher(apiClientHeaderKey)
2293             .matches());
2294   }
2295 
2296   @Test
updateTagExceptionTest()2297   public void updateTagExceptionTest() throws Exception {
2298     ApiException exception =
2299         ApiExceptionFactory.createException(
2300             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2301     mockService.addException(exception);
2302 
2303     try {
2304       Tag tag =
2305           Tag.newBuilder()
2306               .setName(
2307                   "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748")
2308               .setVersion("version351608024")
2309               .build();
2310       FieldMask updateMask = FieldMask.newBuilder().build();
2311       client.updateTag(tag, updateMask);
2312       Assert.fail("No exception raised");
2313     } catch (InvalidArgumentException e) {
2314       // Expected exception.
2315     }
2316   }
2317 
2318   @Test
deleteTagTest()2319   public void deleteTagTest() throws Exception {
2320     Empty expectedResponse = Empty.newBuilder().build();
2321     mockService.addResponse(expectedResponse);
2322 
2323     String name =
2324         "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748";
2325 
2326     client.deleteTag(name);
2327 
2328     List<String> actualRequests = mockService.getRequestPaths();
2329     Assert.assertEquals(1, actualRequests.size());
2330 
2331     String apiClientHeaderKey =
2332         mockService
2333             .getRequestHeaders()
2334             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2335             .iterator()
2336             .next();
2337     Assert.assertTrue(
2338         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2339             .matcher(apiClientHeaderKey)
2340             .matches());
2341   }
2342 
2343   @Test
deleteTagExceptionTest()2344   public void deleteTagExceptionTest() throws Exception {
2345     ApiException exception =
2346         ApiExceptionFactory.createException(
2347             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2348     mockService.addException(exception);
2349 
2350     try {
2351       String name =
2352           "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748";
2353       client.deleteTag(name);
2354       Assert.fail("No exception raised");
2355     } catch (InvalidArgumentException e) {
2356       // Expected exception.
2357     }
2358   }
2359 
2360   @Test
setIamPolicyTest()2361   public void setIamPolicyTest() throws Exception {
2362     Policy expectedResponse =
2363         Policy.newBuilder()
2364             .setVersion(351608024)
2365             .addAllBindings(new ArrayList<Binding>())
2366             .addAllAuditConfigs(new ArrayList<AuditConfig>())
2367             .setEtag(ByteString.EMPTY)
2368             .build();
2369     mockService.addResponse(expectedResponse);
2370 
2371     SetIamPolicyRequest request =
2372         SetIamPolicyRequest.newBuilder()
2373             .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
2374             .setPolicy(Policy.newBuilder().build())
2375             .setUpdateMask(FieldMask.newBuilder().build())
2376             .build();
2377 
2378     Policy actualResponse = client.setIamPolicy(request);
2379     Assert.assertEquals(expectedResponse, actualResponse);
2380 
2381     List<String> actualRequests = mockService.getRequestPaths();
2382     Assert.assertEquals(1, actualRequests.size());
2383 
2384     String apiClientHeaderKey =
2385         mockService
2386             .getRequestHeaders()
2387             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2388             .iterator()
2389             .next();
2390     Assert.assertTrue(
2391         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2392             .matcher(apiClientHeaderKey)
2393             .matches());
2394   }
2395 
2396   @Test
setIamPolicyExceptionTest()2397   public void setIamPolicyExceptionTest() throws Exception {
2398     ApiException exception =
2399         ApiExceptionFactory.createException(
2400             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2401     mockService.addException(exception);
2402 
2403     try {
2404       SetIamPolicyRequest request =
2405           SetIamPolicyRequest.newBuilder()
2406               .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
2407               .setPolicy(Policy.newBuilder().build())
2408               .setUpdateMask(FieldMask.newBuilder().build())
2409               .build();
2410       client.setIamPolicy(request);
2411       Assert.fail("No exception raised");
2412     } catch (InvalidArgumentException e) {
2413       // Expected exception.
2414     }
2415   }
2416 
2417   @Test
getIamPolicyTest()2418   public void getIamPolicyTest() throws Exception {
2419     Policy expectedResponse =
2420         Policy.newBuilder()
2421             .setVersion(351608024)
2422             .addAllBindings(new ArrayList<Binding>())
2423             .addAllAuditConfigs(new ArrayList<AuditConfig>())
2424             .setEtag(ByteString.EMPTY)
2425             .build();
2426     mockService.addResponse(expectedResponse);
2427 
2428     GetIamPolicyRequest request =
2429         GetIamPolicyRequest.newBuilder()
2430             .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
2431             .setOptions(GetPolicyOptions.newBuilder().build())
2432             .build();
2433 
2434     Policy actualResponse = client.getIamPolicy(request);
2435     Assert.assertEquals(expectedResponse, actualResponse);
2436 
2437     List<String> actualRequests = mockService.getRequestPaths();
2438     Assert.assertEquals(1, actualRequests.size());
2439 
2440     String apiClientHeaderKey =
2441         mockService
2442             .getRequestHeaders()
2443             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2444             .iterator()
2445             .next();
2446     Assert.assertTrue(
2447         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2448             .matcher(apiClientHeaderKey)
2449             .matches());
2450   }
2451 
2452   @Test
getIamPolicyExceptionTest()2453   public void getIamPolicyExceptionTest() throws Exception {
2454     ApiException exception =
2455         ApiExceptionFactory.createException(
2456             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2457     mockService.addException(exception);
2458 
2459     try {
2460       GetIamPolicyRequest request =
2461           GetIamPolicyRequest.newBuilder()
2462               .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
2463               .setOptions(GetPolicyOptions.newBuilder().build())
2464               .build();
2465       client.getIamPolicy(request);
2466       Assert.fail("No exception raised");
2467     } catch (InvalidArgumentException e) {
2468       // Expected exception.
2469     }
2470   }
2471 
2472   @Test
testIamPermissionsTest()2473   public void testIamPermissionsTest() throws Exception {
2474     TestIamPermissionsResponse expectedResponse =
2475         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
2476     mockService.addResponse(expectedResponse);
2477 
2478     TestIamPermissionsRequest request =
2479         TestIamPermissionsRequest.newBuilder()
2480             .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
2481             .addAllPermissions(new ArrayList<String>())
2482             .build();
2483 
2484     TestIamPermissionsResponse actualResponse = client.testIamPermissions(request);
2485     Assert.assertEquals(expectedResponse, actualResponse);
2486 
2487     List<String> actualRequests = mockService.getRequestPaths();
2488     Assert.assertEquals(1, actualRequests.size());
2489 
2490     String apiClientHeaderKey =
2491         mockService
2492             .getRequestHeaders()
2493             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2494             .iterator()
2495             .next();
2496     Assert.assertTrue(
2497         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2498             .matcher(apiClientHeaderKey)
2499             .matches());
2500   }
2501 
2502   @Test
testIamPermissionsExceptionTest()2503   public void testIamPermissionsExceptionTest() throws Exception {
2504     ApiException exception =
2505         ApiExceptionFactory.createException(
2506             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2507     mockService.addException(exception);
2508 
2509     try {
2510       TestIamPermissionsRequest request =
2511           TestIamPermissionsRequest.newBuilder()
2512               .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString())
2513               .addAllPermissions(new ArrayList<String>())
2514               .build();
2515       client.testIamPermissions(request);
2516       Assert.fail("No exception raised");
2517     } catch (InvalidArgumentException e) {
2518       // Expected exception.
2519     }
2520   }
2521 
2522   @Test
getProjectSettingsTest()2523   public void getProjectSettingsTest() throws Exception {
2524     ProjectSettings expectedResponse =
2525         ProjectSettings.newBuilder()
2526             .setName(ProjectSettingsName.of("[PROJECT]").toString())
2527             .build();
2528     mockService.addResponse(expectedResponse);
2529 
2530     ProjectSettingsName name = ProjectSettingsName.of("[PROJECT]");
2531 
2532     ProjectSettings actualResponse = client.getProjectSettings(name);
2533     Assert.assertEquals(expectedResponse, actualResponse);
2534 
2535     List<String> actualRequests = mockService.getRequestPaths();
2536     Assert.assertEquals(1, actualRequests.size());
2537 
2538     String apiClientHeaderKey =
2539         mockService
2540             .getRequestHeaders()
2541             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2542             .iterator()
2543             .next();
2544     Assert.assertTrue(
2545         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2546             .matcher(apiClientHeaderKey)
2547             .matches());
2548   }
2549 
2550   @Test
getProjectSettingsExceptionTest()2551   public void getProjectSettingsExceptionTest() throws Exception {
2552     ApiException exception =
2553         ApiExceptionFactory.createException(
2554             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2555     mockService.addException(exception);
2556 
2557     try {
2558       ProjectSettingsName name = ProjectSettingsName.of("[PROJECT]");
2559       client.getProjectSettings(name);
2560       Assert.fail("No exception raised");
2561     } catch (InvalidArgumentException e) {
2562       // Expected exception.
2563     }
2564   }
2565 
2566   @Test
getProjectSettingsTest2()2567   public void getProjectSettingsTest2() throws Exception {
2568     ProjectSettings expectedResponse =
2569         ProjectSettings.newBuilder()
2570             .setName(ProjectSettingsName.of("[PROJECT]").toString())
2571             .build();
2572     mockService.addResponse(expectedResponse);
2573 
2574     String name = "projects/project-9549/projectSettings";
2575 
2576     ProjectSettings actualResponse = client.getProjectSettings(name);
2577     Assert.assertEquals(expectedResponse, actualResponse);
2578 
2579     List<String> actualRequests = mockService.getRequestPaths();
2580     Assert.assertEquals(1, actualRequests.size());
2581 
2582     String apiClientHeaderKey =
2583         mockService
2584             .getRequestHeaders()
2585             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2586             .iterator()
2587             .next();
2588     Assert.assertTrue(
2589         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2590             .matcher(apiClientHeaderKey)
2591             .matches());
2592   }
2593 
2594   @Test
getProjectSettingsExceptionTest2()2595   public void getProjectSettingsExceptionTest2() throws Exception {
2596     ApiException exception =
2597         ApiExceptionFactory.createException(
2598             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2599     mockService.addException(exception);
2600 
2601     try {
2602       String name = "projects/project-9549/projectSettings";
2603       client.getProjectSettings(name);
2604       Assert.fail("No exception raised");
2605     } catch (InvalidArgumentException e) {
2606       // Expected exception.
2607     }
2608   }
2609 
2610   @Test
updateProjectSettingsTest()2611   public void updateProjectSettingsTest() throws Exception {
2612     ProjectSettings expectedResponse =
2613         ProjectSettings.newBuilder()
2614             .setName(ProjectSettingsName.of("[PROJECT]").toString())
2615             .build();
2616     mockService.addResponse(expectedResponse);
2617 
2618     ProjectSettings projectSettings =
2619         ProjectSettings.newBuilder()
2620             .setName(ProjectSettingsName.of("[PROJECT]").toString())
2621             .build();
2622     FieldMask updateMask = FieldMask.newBuilder().build();
2623 
2624     ProjectSettings actualResponse = client.updateProjectSettings(projectSettings, updateMask);
2625     Assert.assertEquals(expectedResponse, actualResponse);
2626 
2627     List<String> actualRequests = mockService.getRequestPaths();
2628     Assert.assertEquals(1, actualRequests.size());
2629 
2630     String apiClientHeaderKey =
2631         mockService
2632             .getRequestHeaders()
2633             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2634             .iterator()
2635             .next();
2636     Assert.assertTrue(
2637         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2638             .matcher(apiClientHeaderKey)
2639             .matches());
2640   }
2641 
2642   @Test
updateProjectSettingsExceptionTest()2643   public void updateProjectSettingsExceptionTest() throws Exception {
2644     ApiException exception =
2645         ApiExceptionFactory.createException(
2646             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2647     mockService.addException(exception);
2648 
2649     try {
2650       ProjectSettings projectSettings =
2651           ProjectSettings.newBuilder()
2652               .setName(ProjectSettingsName.of("[PROJECT]").toString())
2653               .build();
2654       FieldMask updateMask = FieldMask.newBuilder().build();
2655       client.updateProjectSettings(projectSettings, updateMask);
2656       Assert.fail("No exception raised");
2657     } catch (InvalidArgumentException e) {
2658       // Expected exception.
2659     }
2660   }
2661 
2662   @Test
getVPCSCConfigTest()2663   public void getVPCSCConfigTest() throws Exception {
2664     VPCSCConfig expectedResponse =
2665         VPCSCConfig.newBuilder()
2666             .setName(VpcscConfigName.of("[PROJECT]", "[LOCATION]").toString())
2667             .build();
2668     mockService.addResponse(expectedResponse);
2669 
2670     VpcscConfigName name = VpcscConfigName.of("[PROJECT]", "[LOCATION]");
2671 
2672     VPCSCConfig actualResponse = client.getVPCSCConfig(name);
2673     Assert.assertEquals(expectedResponse, actualResponse);
2674 
2675     List<String> actualRequests = mockService.getRequestPaths();
2676     Assert.assertEquals(1, actualRequests.size());
2677 
2678     String apiClientHeaderKey =
2679         mockService
2680             .getRequestHeaders()
2681             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2682             .iterator()
2683             .next();
2684     Assert.assertTrue(
2685         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2686             .matcher(apiClientHeaderKey)
2687             .matches());
2688   }
2689 
2690   @Test
getVPCSCConfigExceptionTest()2691   public void getVPCSCConfigExceptionTest() throws Exception {
2692     ApiException exception =
2693         ApiExceptionFactory.createException(
2694             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2695     mockService.addException(exception);
2696 
2697     try {
2698       VpcscConfigName name = VpcscConfigName.of("[PROJECT]", "[LOCATION]");
2699       client.getVPCSCConfig(name);
2700       Assert.fail("No exception raised");
2701     } catch (InvalidArgumentException e) {
2702       // Expected exception.
2703     }
2704   }
2705 
2706   @Test
getVPCSCConfigTest2()2707   public void getVPCSCConfigTest2() throws Exception {
2708     VPCSCConfig expectedResponse =
2709         VPCSCConfig.newBuilder()
2710             .setName(VpcscConfigName.of("[PROJECT]", "[LOCATION]").toString())
2711             .build();
2712     mockService.addResponse(expectedResponse);
2713 
2714     String name = "projects/project-2118/locations/location-2118/vpcscConfig";
2715 
2716     VPCSCConfig actualResponse = client.getVPCSCConfig(name);
2717     Assert.assertEquals(expectedResponse, actualResponse);
2718 
2719     List<String> actualRequests = mockService.getRequestPaths();
2720     Assert.assertEquals(1, actualRequests.size());
2721 
2722     String apiClientHeaderKey =
2723         mockService
2724             .getRequestHeaders()
2725             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2726             .iterator()
2727             .next();
2728     Assert.assertTrue(
2729         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2730             .matcher(apiClientHeaderKey)
2731             .matches());
2732   }
2733 
2734   @Test
getVPCSCConfigExceptionTest2()2735   public void getVPCSCConfigExceptionTest2() throws Exception {
2736     ApiException exception =
2737         ApiExceptionFactory.createException(
2738             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2739     mockService.addException(exception);
2740 
2741     try {
2742       String name = "projects/project-2118/locations/location-2118/vpcscConfig";
2743       client.getVPCSCConfig(name);
2744       Assert.fail("No exception raised");
2745     } catch (InvalidArgumentException e) {
2746       // Expected exception.
2747     }
2748   }
2749 
2750   @Test
updateVPCSCConfigTest()2751   public void updateVPCSCConfigTest() throws Exception {
2752     VPCSCConfig expectedResponse =
2753         VPCSCConfig.newBuilder()
2754             .setName(VpcscConfigName.of("[PROJECT]", "[LOCATION]").toString())
2755             .build();
2756     mockService.addResponse(expectedResponse);
2757 
2758     VPCSCConfig vpcscConfig =
2759         VPCSCConfig.newBuilder()
2760             .setName(VpcscConfigName.of("[PROJECT]", "[LOCATION]").toString())
2761             .build();
2762     FieldMask updateMask = FieldMask.newBuilder().build();
2763 
2764     VPCSCConfig actualResponse = client.updateVPCSCConfig(vpcscConfig, updateMask);
2765     Assert.assertEquals(expectedResponse, actualResponse);
2766 
2767     List<String> actualRequests = mockService.getRequestPaths();
2768     Assert.assertEquals(1, actualRequests.size());
2769 
2770     String apiClientHeaderKey =
2771         mockService
2772             .getRequestHeaders()
2773             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2774             .iterator()
2775             .next();
2776     Assert.assertTrue(
2777         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2778             .matcher(apiClientHeaderKey)
2779             .matches());
2780   }
2781 
2782   @Test
updateVPCSCConfigExceptionTest()2783   public void updateVPCSCConfigExceptionTest() throws Exception {
2784     ApiException exception =
2785         ApiExceptionFactory.createException(
2786             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2787     mockService.addException(exception);
2788 
2789     try {
2790       VPCSCConfig vpcscConfig =
2791           VPCSCConfig.newBuilder()
2792               .setName(VpcscConfigName.of("[PROJECT]", "[LOCATION]").toString())
2793               .build();
2794       FieldMask updateMask = FieldMask.newBuilder().build();
2795       client.updateVPCSCConfig(vpcscConfig, updateMask);
2796       Assert.fail("No exception raised");
2797     } catch (InvalidArgumentException e) {
2798       // Expected exception.
2799     }
2800   }
2801 
2802   @Test
listLocationsTest()2803   public void listLocationsTest() throws Exception {
2804     Location responsesElement = Location.newBuilder().build();
2805     ListLocationsResponse expectedResponse =
2806         ListLocationsResponse.newBuilder()
2807             .setNextPageToken("")
2808             .addAllLocations(Arrays.asList(responsesElement))
2809             .build();
2810     mockService.addResponse(expectedResponse);
2811 
2812     ListLocationsRequest request =
2813         ListLocationsRequest.newBuilder()
2814             .setName("projects/project-3664")
2815             .setFilter("filter-1274492040")
2816             .setPageSize(883849137)
2817             .setPageToken("pageToken873572522")
2818             .build();
2819 
2820     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
2821 
2822     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
2823 
2824     Assert.assertEquals(1, resources.size());
2825     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
2826 
2827     List<String> actualRequests = mockService.getRequestPaths();
2828     Assert.assertEquals(1, actualRequests.size());
2829 
2830     String apiClientHeaderKey =
2831         mockService
2832             .getRequestHeaders()
2833             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2834             .iterator()
2835             .next();
2836     Assert.assertTrue(
2837         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2838             .matcher(apiClientHeaderKey)
2839             .matches());
2840   }
2841 
2842   @Test
listLocationsExceptionTest()2843   public void listLocationsExceptionTest() throws Exception {
2844     ApiException exception =
2845         ApiExceptionFactory.createException(
2846             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2847     mockService.addException(exception);
2848 
2849     try {
2850       ListLocationsRequest request =
2851           ListLocationsRequest.newBuilder()
2852               .setName("projects/project-3664")
2853               .setFilter("filter-1274492040")
2854               .setPageSize(883849137)
2855               .setPageToken("pageToken873572522")
2856               .build();
2857       client.listLocations(request);
2858       Assert.fail("No exception raised");
2859     } catch (InvalidArgumentException e) {
2860       // Expected exception.
2861     }
2862   }
2863 
2864   @Test
getLocationTest()2865   public void getLocationTest() throws Exception {
2866     Location expectedResponse =
2867         Location.newBuilder()
2868             .setName("name3373707")
2869             .setLocationId("locationId1541836720")
2870             .setDisplayName("displayName1714148973")
2871             .putAllLabels(new HashMap<String, String>())
2872             .setMetadata(Any.newBuilder().build())
2873             .build();
2874     mockService.addResponse(expectedResponse);
2875 
2876     GetLocationRequest request =
2877         GetLocationRequest.newBuilder()
2878             .setName("projects/project-9062/locations/location-9062")
2879             .build();
2880 
2881     Location actualResponse = client.getLocation(request);
2882     Assert.assertEquals(expectedResponse, actualResponse);
2883 
2884     List<String> actualRequests = mockService.getRequestPaths();
2885     Assert.assertEquals(1, actualRequests.size());
2886 
2887     String apiClientHeaderKey =
2888         mockService
2889             .getRequestHeaders()
2890             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2891             .iterator()
2892             .next();
2893     Assert.assertTrue(
2894         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2895             .matcher(apiClientHeaderKey)
2896             .matches());
2897   }
2898 
2899   @Test
getLocationExceptionTest()2900   public void getLocationExceptionTest() throws Exception {
2901     ApiException exception =
2902         ApiExceptionFactory.createException(
2903             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2904     mockService.addException(exception);
2905 
2906     try {
2907       GetLocationRequest request =
2908           GetLocationRequest.newBuilder()
2909               .setName("projects/project-9062/locations/location-9062")
2910               .build();
2911       client.getLocation(request);
2912       Assert.fail("No exception raised");
2913     } catch (InvalidArgumentException e) {
2914       // Expected exception.
2915     }
2916   }
2917 }
2918