diff --git a/google-cloud-artifact-registry/pom.xml b/google-cloud-artifact-registry/pom.xml index d2446081..6e0f894e 100644 --- a/google-cloud-artifact-registry/pom.xml +++ b/google-cloud-artifact-registry/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -90,12 +94,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClient.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClient.java index 60015329..ca04c843 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClient.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClient.java @@ -20,6 +20,7 @@ import com.google.api.core.ApiFutures; import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -36,7 +37,6 @@ import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -125,13 +125,29 @@ * ArtifactRegistryClient.create(artifactRegistrySettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * ArtifactRegistrySettings artifactRegistrySettings =
+ *     ArtifactRegistrySettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             ArtifactRegistrySettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * ArtifactRegistryClient artifactRegistryClient =
+ *     ArtifactRegistryClient.create(artifactRegistrySettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class ArtifactRegistryClient implements BackgroundResource { private final ArtifactRegistrySettings settings; private final ArtifactRegistryStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of ArtifactRegistryClient with default settings. */ public static final ArtifactRegistryClient create() throws IOException { @@ -151,7 +167,6 @@ public static final ArtifactRegistryClient create(ArtifactRegistrySettings setti * Constructs an instance of ArtifactRegistryClient, using the given stub for making calls. This * is for advanced usage - prefer using create(ArtifactRegistrySettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final ArtifactRegistryClient create(ArtifactRegistryStub stub) { return new ArtifactRegistryClient(stub); } @@ -164,21 +179,23 @@ public static final ArtifactRegistryClient create(ArtifactRegistryStub stub) { protected ArtifactRegistryClient(ArtifactRegistrySettings settings) throws IOException { this.settings = settings; this.stub = ((ArtifactRegistryStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected ArtifactRegistryClient(ArtifactRegistryStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final ArtifactRegistrySettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public ArtifactRegistryStub getStub() { return stub; } @@ -187,10 +204,19 @@ public ArtifactRegistryStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Lists docker images. @@ -295,7 +321,7 @@ public final ListDockerImagesPagedResponse listDockerImages(ListDockerImagesRequ * while (true) { * ListDockerImagesResponse response = * artifactRegistryClient.listDockerImagesCallable().call(request); - * for (DockerImage element : response.getResponsesList()) { + * for (DockerImage element : response.getDockerImagesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -707,7 +733,7 @@ public final ListRepositoriesPagedResponse listRepositories(ListRepositoriesRequ * while (true) { * ListRepositoriesResponse response = * artifactRegistryClient.listRepositoriesCallable().call(request); - * for (Repository element : response.getResponsesList()) { + * for (Repository element : response.getRepositoriesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1297,7 +1323,7 @@ public final ListPackagesPagedResponse listPackages(ListPackagesRequest request) * .build(); * while (true) { * ListPackagesResponse response = artifactRegistryClient.listPackagesCallable().call(request); - * for (Package element : response.getResponsesList()) { + * for (Package element : response.getPackagesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1586,7 +1612,7 @@ public final ListVersionsPagedResponse listVersions(ListVersionsRequest request) * .build(); * while (true) { * ListVersionsResponse response = artifactRegistryClient.listVersionsCallable().call(request); - * for (Version element : response.getResponsesList()) { + * for (Version element : response.getVersionsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1882,7 +1908,7 @@ public final UnaryCallable listFilesPa * .build(); * while (true) { * ListFilesResponse response = artifactRegistryClient.listFilesCallable().call(request); - * for (File element : response.getResponsesList()) { + * for (File element : response.getFilesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -2068,7 +2094,7 @@ public final UnaryCallable listTagsPaged * .build(); * while (true) { * ListTagsResponse response = artifactRegistryClient.listTagsCallable().call(request); - * for (Tag element : response.getResponsesList()) { + * for (Tag element : response.getTagsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -2388,9 +2414,7 @@ public final UnaryCallable deleteTagCallable() { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * SetIamPolicyRequest request = * SetIamPolicyRequest.newBuilder() - * .setResource( - * DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - * .toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setPolicy(Policy.newBuilder().build()) * .setUpdateMask(FieldMask.newBuilder().build()) * .build(); @@ -2417,9 +2441,7 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * SetIamPolicyRequest request = * SetIamPolicyRequest.newBuilder() - * .setResource( - * DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - * .toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setPolicy(Policy.newBuilder().build()) * .setUpdateMask(FieldMask.newBuilder().build()) * .build(); @@ -2445,9 +2467,7 @@ public final UnaryCallable setIamPolicyCallable() { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * GetIamPolicyRequest request = * GetIamPolicyRequest.newBuilder() - * .setResource( - * DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - * .toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setOptions(GetPolicyOptions.newBuilder().build()) * .build(); * Policy response = artifactRegistryClient.getIamPolicy(request); @@ -2473,9 +2493,7 @@ public final Policy getIamPolicy(GetIamPolicyRequest request) { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * GetIamPolicyRequest request = * GetIamPolicyRequest.newBuilder() - * .setResource( - * DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - * .toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setOptions(GetPolicyOptions.newBuilder().build()) * .build(); * ApiFuture future = artifactRegistryClient.getIamPolicyCallable().futureCall(request); @@ -2500,9 +2518,7 @@ public final UnaryCallable getIamPolicyCallable() { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * TestIamPermissionsRequest request = * TestIamPermissionsRequest.newBuilder() - * .setResource( - * DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - * .toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .addAllPermissions(new ArrayList()) * .build(); * TestIamPermissionsResponse response = artifactRegistryClient.testIamPermissions(request); @@ -2528,9 +2544,7 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * TestIamPermissionsRequest request = * TestIamPermissionsRequest.newBuilder() - * .setResource( - * DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - * .toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .addAllPermissions(new ArrayList()) * .build(); * ApiFuture future = diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistrySettings.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistrySettings.java index 4d59eaef..fd0751f2 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistrySettings.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/ArtifactRegistrySettings.java @@ -28,6 +28,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -294,11 +295,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return ArtifactRegistryStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return ArtifactRegistryStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return ArtifactRegistryStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return ArtifactRegistryStubSettings.defaultTransportChannelProvider(); } @@ -308,11 +316,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return ArtifactRegistryStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -350,6 +364,11 @@ private static Builder createDefault() { return new Builder(ArtifactRegistryStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(ArtifactRegistryStubSettings.newHttpJsonBuilder()); + } + public ArtifactRegistryStubSettings.Builder getStubSettingsBuilder() { return ((ArtifactRegistryStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStub.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStub.java index 0b5f455c..e63f56e4 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStub.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStub.java @@ -88,7 +88,11 @@ public abstract class ArtifactRegistryStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStubSettings.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStubSettings.java index c03da748..0ba3a47c 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStubSettings.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/ArtifactRegistryStubSettings.java @@ -33,6 +33,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -718,13 +721,17 @@ public UnaryCallSettings getIamPolicySettings() { return updateProjectSettingsSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public ArtifactRegistryStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcArtifactRegistryStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonArtifactRegistryStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -757,18 +764,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(ArtifactRegistryStubSettings.class)) @@ -776,11 +790,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(ArtifactRegistryStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ArtifactRegistryStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -1080,6 +1113,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listDockerImagesSettings() diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/HttpJsonArtifactRegistryCallableFactory.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/HttpJsonArtifactRegistryCallableFactory.java new file mode 100644 index 00000000..ae74a968 --- /dev/null +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/HttpJsonArtifactRegistryCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.artifactregistry.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the ArtifactRegistry service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonArtifactRegistryCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/HttpJsonArtifactRegistryStub.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/HttpJsonArtifactRegistryStub.java new file mode 100644 index 00000000..a6ff2063 --- /dev/null +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1/stub/HttpJsonArtifactRegistryStub.java @@ -0,0 +1,1766 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.artifactregistry.v1.stub; + +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListDockerImagesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListFilesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListPackagesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListRepositoriesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListTagsPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListVersionsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.devtools.artifactregistry.v1.CreateRepositoryRequest; +import com.google.devtools.artifactregistry.v1.CreateTagRequest; +import com.google.devtools.artifactregistry.v1.DeletePackageRequest; +import com.google.devtools.artifactregistry.v1.DeleteRepositoryRequest; +import com.google.devtools.artifactregistry.v1.DeleteTagRequest; +import com.google.devtools.artifactregistry.v1.DeleteVersionRequest; +import com.google.devtools.artifactregistry.v1.DockerImage; +import com.google.devtools.artifactregistry.v1.File; +import com.google.devtools.artifactregistry.v1.GetDockerImageRequest; +import com.google.devtools.artifactregistry.v1.GetFileRequest; +import com.google.devtools.artifactregistry.v1.GetPackageRequest; +import com.google.devtools.artifactregistry.v1.GetProjectSettingsRequest; +import com.google.devtools.artifactregistry.v1.GetRepositoryRequest; +import com.google.devtools.artifactregistry.v1.GetTagRequest; +import com.google.devtools.artifactregistry.v1.GetVersionRequest; +import com.google.devtools.artifactregistry.v1.ImportAptArtifactsMetadata; +import com.google.devtools.artifactregistry.v1.ImportAptArtifactsRequest; +import com.google.devtools.artifactregistry.v1.ImportAptArtifactsResponse; +import com.google.devtools.artifactregistry.v1.ImportYumArtifactsMetadata; +import com.google.devtools.artifactregistry.v1.ImportYumArtifactsRequest; +import com.google.devtools.artifactregistry.v1.ImportYumArtifactsResponse; +import com.google.devtools.artifactregistry.v1.ListDockerImagesRequest; +import com.google.devtools.artifactregistry.v1.ListDockerImagesResponse; +import com.google.devtools.artifactregistry.v1.ListFilesRequest; +import com.google.devtools.artifactregistry.v1.ListFilesResponse; +import com.google.devtools.artifactregistry.v1.ListPackagesRequest; +import com.google.devtools.artifactregistry.v1.ListPackagesResponse; +import com.google.devtools.artifactregistry.v1.ListRepositoriesRequest; +import com.google.devtools.artifactregistry.v1.ListRepositoriesResponse; +import com.google.devtools.artifactregistry.v1.ListTagsRequest; +import com.google.devtools.artifactregistry.v1.ListTagsResponse; +import com.google.devtools.artifactregistry.v1.ListVersionsRequest; +import com.google.devtools.artifactregistry.v1.ListVersionsResponse; +import com.google.devtools.artifactregistry.v1.OperationMetadata; +import com.google.devtools.artifactregistry.v1.Package; +import com.google.devtools.artifactregistry.v1.ProjectSettings; +import com.google.devtools.artifactregistry.v1.Repository; +import com.google.devtools.artifactregistry.v1.Tag; +import com.google.devtools.artifactregistry.v1.UpdateProjectSettingsRequest; +import com.google.devtools.artifactregistry.v1.UpdateRepositoryRequest; +import com.google.devtools.artifactregistry.v1.UpdateTagRequest; +import com.google.devtools.artifactregistry.v1.Version; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the ArtifactRegistry service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonArtifactRegistryStub extends ArtifactRegistryStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(ImportYumArtifactsResponse.getDescriptor()) + .add(ImportAptArtifactsResponse.getDescriptor()) + .add(ImportYumArtifactsMetadata.getDescriptor()) + .add(ImportAptArtifactsMetadata.getDescriptor()) + .add(Repository.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + listDockerImagesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/ListDockerImages") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*}/dockerImages", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListDockerImagesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getDockerImageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/GetDockerImage") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/dockerImages/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(DockerImage.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + importAptArtifactsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/ImportAptArtifacts") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*}/aptArtifacts:import", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ImportAptArtifactsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + importYumArtifactsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/ImportYumArtifacts") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*}/yumArtifacts:import", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ImportYumArtifactsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listRepositoriesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/ListRepositories") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/repositories", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListRepositoriesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/GetRepository") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Repository.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/CreateRepository") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*}/repositories", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "repositoryId", request.getRepositoryId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("repository", request.getRepository())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateRepositoryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/UpdateRepository") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{repository.name=projects/*/locations/*/repositories/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "repository.name", request.getRepository().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("repository", request.getRepository())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Repository.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/DeleteRepository") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteRepositoryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listPackagesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/ListPackages") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*}/packages", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListPackagesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getPackageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/GetPackage") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/packages/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Package.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deletePackageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/DeletePackage") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/packages/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeletePackageRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listVersionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/ListVersions") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*/packages/*}/versions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListVersionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/GetVersion") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/packages/*/versions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Version.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/DeleteVersion") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/packages/*/versions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "force", request.getForce()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteVersionRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listFilesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/ListFiles") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*}/files", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListFilesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getFileMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/GetFile") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/files/**}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(File.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listTagsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/ListTags") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*/packages/*}/tags", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListTagsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/GetTag") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/packages/*/tags/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Tag.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/CreateTag") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*/locations/*/repositories/*/packages/*}/tags", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "tagId", request.getTagId()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("tag", request.getTag())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Tag.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/UpdateTag") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{tag.name=projects/*/locations/*/repositories/*/packages/*/tags/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "tag.name", request.getTag().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("tag", request.getTag())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Tag.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1.ArtifactRegistry/DeleteTag") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/locations/*/repositories/*/packages/*/tags/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/repositories/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/repositories/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "options", request.getOptions()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=projects/*/locations/*/repositories/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getProjectSettingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/GetProjectSettings") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/projectSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ProjectSettings.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateProjectSettingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1.ArtifactRegistry/UpdateProjectSettings") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{projectSettings.name=projects/*/projectSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "projectSettings.name", + request.getProjectSettings().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("projectSettings", request.getProjectSettings())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ProjectSettings.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listDockerImagesCallable; + private final UnaryCallable + listDockerImagesPagedCallable; + private final UnaryCallable getDockerImageCallable; + private final UnaryCallable importAptArtifactsCallable; + private final OperationCallable< + ImportAptArtifactsRequest, ImportAptArtifactsResponse, ImportAptArtifactsMetadata> + importAptArtifactsOperationCallable; + private final UnaryCallable importYumArtifactsCallable; + private final OperationCallable< + ImportYumArtifactsRequest, ImportYumArtifactsResponse, ImportYumArtifactsMetadata> + importYumArtifactsOperationCallable; + private final UnaryCallable + listRepositoriesCallable; + private final UnaryCallable + listRepositoriesPagedCallable; + private final UnaryCallable getRepositoryCallable; + private final UnaryCallable createRepositoryCallable; + private final OperationCallable + createRepositoryOperationCallable; + private final UnaryCallable updateRepositoryCallable; + private final UnaryCallable deleteRepositoryCallable; + private final OperationCallable + deleteRepositoryOperationCallable; + private final UnaryCallable listPackagesCallable; + private final UnaryCallable + listPackagesPagedCallable; + private final UnaryCallable getPackageCallable; + private final UnaryCallable deletePackageCallable; + private final OperationCallable + deletePackageOperationCallable; + private final UnaryCallable listVersionsCallable; + private final UnaryCallable + listVersionsPagedCallable; + private final UnaryCallable getVersionCallable; + private final UnaryCallable deleteVersionCallable; + private final OperationCallable + deleteVersionOperationCallable; + private final UnaryCallable listFilesCallable; + private final UnaryCallable listFilesPagedCallable; + private final UnaryCallable getFileCallable; + private final UnaryCallable listTagsCallable; + private final UnaryCallable listTagsPagedCallable; + private final UnaryCallable getTagCallable; + private final UnaryCallable createTagCallable; + private final UnaryCallable updateTagCallable; + private final UnaryCallable deleteTagCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + private final UnaryCallable + getProjectSettingsCallable; + private final UnaryCallable + updateProjectSettingsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonArtifactRegistryStub create(ArtifactRegistryStubSettings settings) + throws IOException { + return new HttpJsonArtifactRegistryStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonArtifactRegistryStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonArtifactRegistryStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonArtifactRegistryStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonArtifactRegistryCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonArtifactRegistryStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + listDockerImagesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listDockerImagesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getDockerImageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getDockerImageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importAptArtifactsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importAptArtifactsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importYumArtifactsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importYumArtifactsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listRepositoriesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listRepositoriesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listPackagesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listPackagesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getPackageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getPackageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deletePackageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deletePackageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listVersionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listVersionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listFilesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listFilesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getFileTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getFileMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listTagsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listTagsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getProjectSettingsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getProjectSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateProjectSettingsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateProjectSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listDockerImagesCallable = + callableFactory.createUnaryCallable( + listDockerImagesTransportSettings, settings.listDockerImagesSettings(), clientContext); + this.listDockerImagesPagedCallable = + callableFactory.createPagedCallable( + listDockerImagesTransportSettings, settings.listDockerImagesSettings(), clientContext); + this.getDockerImageCallable = + callableFactory.createUnaryCallable( + getDockerImageTransportSettings, settings.getDockerImageSettings(), clientContext); + this.importAptArtifactsCallable = + callableFactory.createUnaryCallable( + importAptArtifactsTransportSettings, + settings.importAptArtifactsSettings(), + clientContext); + this.importAptArtifactsOperationCallable = + callableFactory.createOperationCallable( + importAptArtifactsTransportSettings, + settings.importAptArtifactsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.importYumArtifactsCallable = + callableFactory.createUnaryCallable( + importYumArtifactsTransportSettings, + settings.importYumArtifactsSettings(), + clientContext); + this.importYumArtifactsOperationCallable = + callableFactory.createOperationCallable( + importYumArtifactsTransportSettings, + settings.importYumArtifactsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listRepositoriesCallable = + callableFactory.createUnaryCallable( + listRepositoriesTransportSettings, settings.listRepositoriesSettings(), clientContext); + this.listRepositoriesPagedCallable = + callableFactory.createPagedCallable( + listRepositoriesTransportSettings, settings.listRepositoriesSettings(), clientContext); + this.getRepositoryCallable = + callableFactory.createUnaryCallable( + getRepositoryTransportSettings, settings.getRepositorySettings(), clientContext); + this.createRepositoryCallable = + callableFactory.createUnaryCallable( + createRepositoryTransportSettings, settings.createRepositorySettings(), clientContext); + this.createRepositoryOperationCallable = + callableFactory.createOperationCallable( + createRepositoryTransportSettings, + settings.createRepositoryOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateRepositoryCallable = + callableFactory.createUnaryCallable( + updateRepositoryTransportSettings, settings.updateRepositorySettings(), clientContext); + this.deleteRepositoryCallable = + callableFactory.createUnaryCallable( + deleteRepositoryTransportSettings, settings.deleteRepositorySettings(), clientContext); + this.deleteRepositoryOperationCallable = + callableFactory.createOperationCallable( + deleteRepositoryTransportSettings, + settings.deleteRepositoryOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listPackagesCallable = + callableFactory.createUnaryCallable( + listPackagesTransportSettings, settings.listPackagesSettings(), clientContext); + this.listPackagesPagedCallable = + callableFactory.createPagedCallable( + listPackagesTransportSettings, settings.listPackagesSettings(), clientContext); + this.getPackageCallable = + callableFactory.createUnaryCallable( + getPackageTransportSettings, settings.getPackageSettings(), clientContext); + this.deletePackageCallable = + callableFactory.createUnaryCallable( + deletePackageTransportSettings, settings.deletePackageSettings(), clientContext); + this.deletePackageOperationCallable = + callableFactory.createOperationCallable( + deletePackageTransportSettings, + settings.deletePackageOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listVersionsCallable = + callableFactory.createUnaryCallable( + listVersionsTransportSettings, settings.listVersionsSettings(), clientContext); + this.listVersionsPagedCallable = + callableFactory.createPagedCallable( + listVersionsTransportSettings, settings.listVersionsSettings(), clientContext); + this.getVersionCallable = + callableFactory.createUnaryCallable( + getVersionTransportSettings, settings.getVersionSettings(), clientContext); + this.deleteVersionCallable = + callableFactory.createUnaryCallable( + deleteVersionTransportSettings, settings.deleteVersionSettings(), clientContext); + this.deleteVersionOperationCallable = + callableFactory.createOperationCallable( + deleteVersionTransportSettings, + settings.deleteVersionOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listFilesCallable = + callableFactory.createUnaryCallable( + listFilesTransportSettings, settings.listFilesSettings(), clientContext); + this.listFilesPagedCallable = + callableFactory.createPagedCallable( + listFilesTransportSettings, settings.listFilesSettings(), clientContext); + this.getFileCallable = + callableFactory.createUnaryCallable( + getFileTransportSettings, settings.getFileSettings(), clientContext); + this.listTagsCallable = + callableFactory.createUnaryCallable( + listTagsTransportSettings, settings.listTagsSettings(), clientContext); + this.listTagsPagedCallable = + callableFactory.createPagedCallable( + listTagsTransportSettings, settings.listTagsSettings(), clientContext); + this.getTagCallable = + callableFactory.createUnaryCallable( + getTagTransportSettings, settings.getTagSettings(), clientContext); + this.createTagCallable = + callableFactory.createUnaryCallable( + createTagTransportSettings, settings.createTagSettings(), clientContext); + this.updateTagCallable = + callableFactory.createUnaryCallable( + updateTagTransportSettings, settings.updateTagSettings(), clientContext); + this.deleteTagCallable = + callableFactory.createUnaryCallable( + deleteTagTransportSettings, settings.deleteTagSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + this.getProjectSettingsCallable = + callableFactory.createUnaryCallable( + getProjectSettingsTransportSettings, + settings.getProjectSettingsSettings(), + clientContext); + this.updateProjectSettingsCallable = + callableFactory.createUnaryCallable( + updateProjectSettingsTransportSettings, + settings.updateProjectSettingsSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listDockerImagesMethodDescriptor); + methodDescriptors.add(getDockerImageMethodDescriptor); + methodDescriptors.add(importAptArtifactsMethodDescriptor); + methodDescriptors.add(importYumArtifactsMethodDescriptor); + methodDescriptors.add(listRepositoriesMethodDescriptor); + methodDescriptors.add(getRepositoryMethodDescriptor); + methodDescriptors.add(createRepositoryMethodDescriptor); + methodDescriptors.add(updateRepositoryMethodDescriptor); + methodDescriptors.add(deleteRepositoryMethodDescriptor); + methodDescriptors.add(listPackagesMethodDescriptor); + methodDescriptors.add(getPackageMethodDescriptor); + methodDescriptors.add(deletePackageMethodDescriptor); + methodDescriptors.add(listVersionsMethodDescriptor); + methodDescriptors.add(getVersionMethodDescriptor); + methodDescriptors.add(deleteVersionMethodDescriptor); + methodDescriptors.add(listFilesMethodDescriptor); + methodDescriptors.add(getFileMethodDescriptor); + methodDescriptors.add(listTagsMethodDescriptor); + methodDescriptors.add(getTagMethodDescriptor); + methodDescriptors.add(createTagMethodDescriptor); + methodDescriptors.add(updateTagMethodDescriptor); + methodDescriptors.add(deleteTagMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + methodDescriptors.add(getProjectSettingsMethodDescriptor); + methodDescriptors.add(updateProjectSettingsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + listDockerImagesCallable() { + return listDockerImagesCallable; + } + + @Override + public UnaryCallable + listDockerImagesPagedCallable() { + return listDockerImagesPagedCallable; + } + + @Override + public UnaryCallable getDockerImageCallable() { + return getDockerImageCallable; + } + + @Override + public UnaryCallable importAptArtifactsCallable() { + return importAptArtifactsCallable; + } + + @Override + public OperationCallable< + ImportAptArtifactsRequest, ImportAptArtifactsResponse, ImportAptArtifactsMetadata> + importAptArtifactsOperationCallable() { + return importAptArtifactsOperationCallable; + } + + @Override + public UnaryCallable importYumArtifactsCallable() { + return importYumArtifactsCallable; + } + + @Override + public OperationCallable< + ImportYumArtifactsRequest, ImportYumArtifactsResponse, ImportYumArtifactsMetadata> + importYumArtifactsOperationCallable() { + return importYumArtifactsOperationCallable; + } + + @Override + public UnaryCallable + listRepositoriesCallable() { + return listRepositoriesCallable; + } + + @Override + public UnaryCallable + listRepositoriesPagedCallable() { + return listRepositoriesPagedCallable; + } + + @Override + public UnaryCallable getRepositoryCallable() { + return getRepositoryCallable; + } + + @Override + public UnaryCallable createRepositoryCallable() { + return createRepositoryCallable; + } + + @Override + public OperationCallable + createRepositoryOperationCallable() { + return createRepositoryOperationCallable; + } + + @Override + public UnaryCallable updateRepositoryCallable() { + return updateRepositoryCallable; + } + + @Override + public UnaryCallable deleteRepositoryCallable() { + return deleteRepositoryCallable; + } + + @Override + public OperationCallable + deleteRepositoryOperationCallable() { + return deleteRepositoryOperationCallable; + } + + @Override + public UnaryCallable listPackagesCallable() { + return listPackagesCallable; + } + + @Override + public UnaryCallable listPackagesPagedCallable() { + return listPackagesPagedCallable; + } + + @Override + public UnaryCallable getPackageCallable() { + return getPackageCallable; + } + + @Override + public UnaryCallable deletePackageCallable() { + return deletePackageCallable; + } + + @Override + public OperationCallable + deletePackageOperationCallable() { + return deletePackageOperationCallable; + } + + @Override + public UnaryCallable listVersionsCallable() { + return listVersionsCallable; + } + + @Override + public UnaryCallable listVersionsPagedCallable() { + return listVersionsPagedCallable; + } + + @Override + public UnaryCallable getVersionCallable() { + return getVersionCallable; + } + + @Override + public UnaryCallable deleteVersionCallable() { + return deleteVersionCallable; + } + + @Override + public OperationCallable + deleteVersionOperationCallable() { + return deleteVersionOperationCallable; + } + + @Override + public UnaryCallable listFilesCallable() { + return listFilesCallable; + } + + @Override + public UnaryCallable listFilesPagedCallable() { + return listFilesPagedCallable; + } + + @Override + public UnaryCallable getFileCallable() { + return getFileCallable; + } + + @Override + public UnaryCallable listTagsCallable() { + return listTagsCallable; + } + + @Override + public UnaryCallable listTagsPagedCallable() { + return listTagsPagedCallable; + } + + @Override + public UnaryCallable getTagCallable() { + return getTagCallable; + } + + @Override + public UnaryCallable createTagCallable() { + return createTagCallable; + } + + @Override + public UnaryCallable updateTagCallable() { + return updateTagCallable; + } + + @Override + public UnaryCallable deleteTagCallable() { + return deleteTagCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public UnaryCallable getProjectSettingsCallable() { + return getProjectSettingsCallable; + } + + @Override + public UnaryCallable + updateProjectSettingsCallable() { + return updateProjectSettingsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClient.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClient.java index 50503b9f..acadd9db 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClient.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClient.java @@ -20,6 +20,7 @@ import com.google.api.core.ApiFutures; import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -36,7 +37,6 @@ import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -124,6 +124,21 @@ * ArtifactRegistryClient.create(artifactRegistrySettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * ArtifactRegistrySettings artifactRegistrySettings =
+ *     ArtifactRegistrySettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             ArtifactRegistrySettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * ArtifactRegistryClient artifactRegistryClient =
+ *     ArtifactRegistryClient.create(artifactRegistrySettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -131,7 +146,8 @@ public class ArtifactRegistryClient implements BackgroundResource { private final ArtifactRegistrySettings settings; private final ArtifactRegistryStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of ArtifactRegistryClient with default settings. */ public static final ArtifactRegistryClient create() throws IOException { @@ -151,7 +167,6 @@ public static final ArtifactRegistryClient create(ArtifactRegistrySettings setti * Constructs an instance of ArtifactRegistryClient, using the given stub for making calls. This * is for advanced usage - prefer using create(ArtifactRegistrySettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final ArtifactRegistryClient create(ArtifactRegistryStub stub) { return new ArtifactRegistryClient(stub); } @@ -164,21 +179,23 @@ public static final ArtifactRegistryClient create(ArtifactRegistryStub stub) { protected ArtifactRegistryClient(ArtifactRegistrySettings settings) throws IOException { this.settings = settings; this.stub = ((ArtifactRegistryStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected ArtifactRegistryClient(ArtifactRegistryStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final ArtifactRegistrySettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public ArtifactRegistryStub getStub() { return stub; } @@ -187,10 +204,19 @@ public ArtifactRegistryStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Imports Apt artifacts. The returned Operation will complete once the resources are imported. @@ -481,7 +507,7 @@ public final ListRepositoriesPagedResponse listRepositories(ListRepositoriesRequ * while (true) { * ListRepositoriesResponse response = * artifactRegistryClient.listRepositoriesCallable().call(request); - * for (Repository element : response.getResponsesList()) { + * for (Repository element : response.getRepositoriesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1071,7 +1097,7 @@ public final ListPackagesPagedResponse listPackages(ListPackagesRequest request) * .build(); * while (true) { * ListPackagesResponse response = artifactRegistryClient.listPackagesCallable().call(request); - * for (Package element : response.getResponsesList()) { + * for (Package element : response.getPackagesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1360,7 +1386,7 @@ public final ListVersionsPagedResponse listVersions(ListVersionsRequest request) * .build(); * while (true) { * ListVersionsResponse response = artifactRegistryClient.listVersionsCallable().call(request); - * for (Version element : response.getResponsesList()) { + * for (Version element : response.getVersionsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1653,7 +1679,7 @@ public final UnaryCallable listFilesPa * .build(); * while (true) { * ListFilesResponse response = artifactRegistryClient.listFilesCallable().call(request); - * for (File element : response.getResponsesList()) { + * for (File element : response.getFilesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1839,7 +1865,7 @@ public final UnaryCallable listTagsPaged * .build(); * while (true) { * ListTagsResponse response = artifactRegistryClient.listTagsCallable().call(request); - * for (Tag element : response.getResponsesList()) { + * for (Tag element : response.getTagsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -2159,7 +2185,7 @@ public final UnaryCallable deleteTagCallable() { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * SetIamPolicyRequest request = * SetIamPolicyRequest.newBuilder() - * .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setPolicy(Policy.newBuilder().build()) * .setUpdateMask(FieldMask.newBuilder().build()) * .build(); @@ -2186,7 +2212,7 @@ public final Policy setIamPolicy(SetIamPolicyRequest request) { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * SetIamPolicyRequest request = * SetIamPolicyRequest.newBuilder() - * .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setPolicy(Policy.newBuilder().build()) * .setUpdateMask(FieldMask.newBuilder().build()) * .build(); @@ -2212,7 +2238,7 @@ public final UnaryCallable setIamPolicyCallable() { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * GetIamPolicyRequest request = * GetIamPolicyRequest.newBuilder() - * .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setOptions(GetPolicyOptions.newBuilder().build()) * .build(); * Policy response = artifactRegistryClient.getIamPolicy(request); @@ -2238,7 +2264,7 @@ public final Policy getIamPolicy(GetIamPolicyRequest request) { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * GetIamPolicyRequest request = * GetIamPolicyRequest.newBuilder() - * .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .setOptions(GetPolicyOptions.newBuilder().build()) * .build(); * ApiFuture future = artifactRegistryClient.getIamPolicyCallable().futureCall(request); @@ -2263,7 +2289,7 @@ public final UnaryCallable getIamPolicyCallable() { * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * TestIamPermissionsRequest request = * TestIamPermissionsRequest.newBuilder() - * .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .addAllPermissions(new ArrayList()) * .build(); * TestIamPermissionsResponse response = artifactRegistryClient.testIamPermissions(request); @@ -2289,7 +2315,7 @@ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsReq * try (ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.create()) { * TestIamPermissionsRequest request = * TestIamPermissionsRequest.newBuilder() - * .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + * .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) * .addAllPermissions(new ArrayList()) * .build(); * ApiFuture future = diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistrySettings.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistrySettings.java index 3968efc5..5a68e3f9 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistrySettings.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistrySettings.java @@ -27,6 +27,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -282,11 +283,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return ArtifactRegistryStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return ArtifactRegistryStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return ArtifactRegistryStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return ArtifactRegistryStubSettings.defaultTransportChannelProvider(); } @@ -296,11 +304,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return ArtifactRegistryStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -338,6 +352,11 @@ private static Builder createDefault() { return new Builder(ArtifactRegistryStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(ArtifactRegistryStubSettings.newHttpJsonBuilder()); + } + public ArtifactRegistryStubSettings.Builder getStubSettingsBuilder() { return ((ArtifactRegistryStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStub.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStub.java index fd89506e..09bb9e30 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStub.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStub.java @@ -85,7 +85,11 @@ public abstract class ArtifactRegistryStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public OperationCallable< diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStubSettings.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStubSettings.java index ca96c19f..a85f453f 100644 --- a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStubSettings.java +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/ArtifactRegistryStubSettings.java @@ -32,6 +32,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -639,13 +642,17 @@ public UnaryCallSettings getIamPolicySettings() { return updateProjectSettingsSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public ArtifactRegistryStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcArtifactRegistryStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonArtifactRegistryStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -678,18 +685,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(ArtifactRegistryStubSettings.class)) @@ -697,11 +711,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(ArtifactRegistryStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ArtifactRegistryStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -1003,6 +1036,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .importAptArtifactsSettings() diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/HttpJsonArtifactRegistryCallableFactory.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/HttpJsonArtifactRegistryCallableFactory.java new file mode 100644 index 00000000..797c2d07 --- /dev/null +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/HttpJsonArtifactRegistryCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.artifactregistry.v1beta2.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the ArtifactRegistry service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonArtifactRegistryCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/HttpJsonArtifactRegistryStub.java b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/HttpJsonArtifactRegistryStub.java new file mode 100644 index 00000000..1b4afb9e --- /dev/null +++ b/google-cloud-artifact-registry/src/main/java/com/google/devtools/artifactregistry/v1beta2/stub/HttpJsonArtifactRegistryStub.java @@ -0,0 +1,1648 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.artifactregistry.v1beta2.stub; + +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListFilesPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListPackagesPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListRepositoriesPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListTagsPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListVersionsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.devtools.artifactregistry.v1beta2.CreateRepositoryRequest; +import com.google.devtools.artifactregistry.v1beta2.CreateTagRequest; +import com.google.devtools.artifactregistry.v1beta2.DeletePackageRequest; +import com.google.devtools.artifactregistry.v1beta2.DeleteRepositoryRequest; +import com.google.devtools.artifactregistry.v1beta2.DeleteTagRequest; +import com.google.devtools.artifactregistry.v1beta2.DeleteVersionRequest; +import com.google.devtools.artifactregistry.v1beta2.File; +import com.google.devtools.artifactregistry.v1beta2.GetFileRequest; +import com.google.devtools.artifactregistry.v1beta2.GetPackageRequest; +import com.google.devtools.artifactregistry.v1beta2.GetProjectSettingsRequest; +import com.google.devtools.artifactregistry.v1beta2.GetRepositoryRequest; +import com.google.devtools.artifactregistry.v1beta2.GetTagRequest; +import com.google.devtools.artifactregistry.v1beta2.GetVersionRequest; +import com.google.devtools.artifactregistry.v1beta2.ImportAptArtifactsMetadata; +import com.google.devtools.artifactregistry.v1beta2.ImportAptArtifactsRequest; +import com.google.devtools.artifactregistry.v1beta2.ImportAptArtifactsResponse; +import com.google.devtools.artifactregistry.v1beta2.ImportYumArtifactsMetadata; +import com.google.devtools.artifactregistry.v1beta2.ImportYumArtifactsRequest; +import com.google.devtools.artifactregistry.v1beta2.ImportYumArtifactsResponse; +import com.google.devtools.artifactregistry.v1beta2.ListFilesRequest; +import com.google.devtools.artifactregistry.v1beta2.ListFilesResponse; +import com.google.devtools.artifactregistry.v1beta2.ListPackagesRequest; +import com.google.devtools.artifactregistry.v1beta2.ListPackagesResponse; +import com.google.devtools.artifactregistry.v1beta2.ListRepositoriesRequest; +import com.google.devtools.artifactregistry.v1beta2.ListRepositoriesResponse; +import com.google.devtools.artifactregistry.v1beta2.ListTagsRequest; +import com.google.devtools.artifactregistry.v1beta2.ListTagsResponse; +import com.google.devtools.artifactregistry.v1beta2.ListVersionsRequest; +import com.google.devtools.artifactregistry.v1beta2.ListVersionsResponse; +import com.google.devtools.artifactregistry.v1beta2.OperationMetadata; +import com.google.devtools.artifactregistry.v1beta2.Package; +import com.google.devtools.artifactregistry.v1beta2.ProjectSettings; +import com.google.devtools.artifactregistry.v1beta2.Repository; +import com.google.devtools.artifactregistry.v1beta2.Tag; +import com.google.devtools.artifactregistry.v1beta2.UpdateProjectSettingsRequest; +import com.google.devtools.artifactregistry.v1beta2.UpdateRepositoryRequest; +import com.google.devtools.artifactregistry.v1beta2.UpdateTagRequest; +import com.google.devtools.artifactregistry.v1beta2.Version; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the ArtifactRegistry service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonArtifactRegistryStub extends ArtifactRegistryStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(Repository.getDescriptor()) + .add(ImportYumArtifactsResponse.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(ImportYumArtifactsMetadata.getDescriptor()) + .add(ImportAptArtifactsMetadata.getDescriptor()) + .add(ImportAptArtifactsResponse.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + importAptArtifactsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ImportAptArtifacts") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*}/aptArtifacts:import", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ImportAptArtifactsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + importYumArtifactsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ImportYumArtifacts") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*}/yumArtifacts:import", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ImportYumArtifactsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listRepositoriesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ListRepositories") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*}/repositories", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListRepositoriesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetRepository") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Repository.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/CreateRepository") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*}/repositories", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "repositoryId", request.getRepositoryId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("repository", request.getRepository())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateRepositoryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/UpdateRepository") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{repository.name=projects/*/locations/*/repositories/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "repository.name", request.getRepository().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("repository", request.getRepository())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Repository.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteRepositoryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/DeleteRepository") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteRepositoryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listPackagesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ListPackages") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*}/packages", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListPackagesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getPackageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetPackage") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/packages/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Package.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deletePackageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/DeletePackage") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/packages/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeletePackageRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listVersionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ListVersions") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*/packages/*}/versions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListVersionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetVersion") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/packages/*/versions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Version.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteVersionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/DeleteVersion") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/packages/*/versions/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "force", request.getForce()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteVersionRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listFilesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ListFiles") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*}/files", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListFilesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getFileMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetFile") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/files/**}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(File.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listTagsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/ListTags") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*/packages/*}/tags", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListTagsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetTag") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/packages/*/tags/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Tag.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/CreateTag") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{parent=projects/*/locations/*/repositories/*/packages/*}/tags", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "tagId", request.getTagId()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("tag", request.getTag())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Tag.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/UpdateTag") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{tag.name=projects/*/locations/*/repositories/*/packages/*/tags/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "tag.name", request.getTag().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("tag", request.getTag())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Tag.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteTagMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.devtools.artifactregistry.v1beta2.ArtifactRegistry/DeleteTag") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/locations/*/repositories/*/packages/*/tags/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{resource=projects/*/locations/*/repositories/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{resource=projects/*/locations/*/repositories/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "options", request.getOptions()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{resource=projects/*/locations/*/repositories/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getProjectSettingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/GetProjectSettings") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{name=projects/*/projectSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ProjectSettings.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateProjectSettingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.devtools.artifactregistry.v1beta2.ArtifactRegistry/UpdateProjectSettings") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta2/{projectSettings.name=projects/*/projectSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "projectSettings.name", + request.getProjectSettings().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("projectSettings", request.getProjectSettings())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ProjectSettings.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable importAptArtifactsCallable; + private final OperationCallable< + ImportAptArtifactsRequest, ImportAptArtifactsResponse, ImportAptArtifactsMetadata> + importAptArtifactsOperationCallable; + private final UnaryCallable importYumArtifactsCallable; + private final OperationCallable< + ImportYumArtifactsRequest, ImportYumArtifactsResponse, ImportYumArtifactsMetadata> + importYumArtifactsOperationCallable; + private final UnaryCallable + listRepositoriesCallable; + private final UnaryCallable + listRepositoriesPagedCallable; + private final UnaryCallable getRepositoryCallable; + private final UnaryCallable createRepositoryCallable; + private final OperationCallable + createRepositoryOperationCallable; + private final UnaryCallable updateRepositoryCallable; + private final UnaryCallable deleteRepositoryCallable; + private final OperationCallable + deleteRepositoryOperationCallable; + private final UnaryCallable listPackagesCallable; + private final UnaryCallable + listPackagesPagedCallable; + private final UnaryCallable getPackageCallable; + private final UnaryCallable deletePackageCallable; + private final OperationCallable + deletePackageOperationCallable; + private final UnaryCallable listVersionsCallable; + private final UnaryCallable + listVersionsPagedCallable; + private final UnaryCallable getVersionCallable; + private final UnaryCallable deleteVersionCallable; + private final OperationCallable + deleteVersionOperationCallable; + private final UnaryCallable listFilesCallable; + private final UnaryCallable listFilesPagedCallable; + private final UnaryCallable getFileCallable; + private final UnaryCallable listTagsCallable; + private final UnaryCallable listTagsPagedCallable; + private final UnaryCallable getTagCallable; + private final UnaryCallable createTagCallable; + private final UnaryCallable updateTagCallable; + private final UnaryCallable deleteTagCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + private final UnaryCallable + getProjectSettingsCallable; + private final UnaryCallable + updateProjectSettingsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonArtifactRegistryStub create(ArtifactRegistryStubSettings settings) + throws IOException { + return new HttpJsonArtifactRegistryStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonArtifactRegistryStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonArtifactRegistryStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonArtifactRegistryStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonArtifactRegistryCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonArtifactRegistryStub, using the given settings. This is + * protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonArtifactRegistryStub( + ArtifactRegistryStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings importAptArtifactsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importAptArtifactsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importYumArtifactsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importYumArtifactsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listRepositoriesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listRepositoriesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteRepositoryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteRepositoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listPackagesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listPackagesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getPackageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getPackageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deletePackageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deletePackageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listVersionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listVersionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteVersionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteVersionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listFilesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listFilesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getFileTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getFileMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listTagsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listTagsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteTagTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteTagMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getProjectSettingsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getProjectSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateProjectSettingsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateProjectSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.importAptArtifactsCallable = + callableFactory.createUnaryCallable( + importAptArtifactsTransportSettings, + settings.importAptArtifactsSettings(), + clientContext); + this.importAptArtifactsOperationCallable = + callableFactory.createOperationCallable( + importAptArtifactsTransportSettings, + settings.importAptArtifactsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.importYumArtifactsCallable = + callableFactory.createUnaryCallable( + importYumArtifactsTransportSettings, + settings.importYumArtifactsSettings(), + clientContext); + this.importYumArtifactsOperationCallable = + callableFactory.createOperationCallable( + importYumArtifactsTransportSettings, + settings.importYumArtifactsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listRepositoriesCallable = + callableFactory.createUnaryCallable( + listRepositoriesTransportSettings, settings.listRepositoriesSettings(), clientContext); + this.listRepositoriesPagedCallable = + callableFactory.createPagedCallable( + listRepositoriesTransportSettings, settings.listRepositoriesSettings(), clientContext); + this.getRepositoryCallable = + callableFactory.createUnaryCallable( + getRepositoryTransportSettings, settings.getRepositorySettings(), clientContext); + this.createRepositoryCallable = + callableFactory.createUnaryCallable( + createRepositoryTransportSettings, settings.createRepositorySettings(), clientContext); + this.createRepositoryOperationCallable = + callableFactory.createOperationCallable( + createRepositoryTransportSettings, + settings.createRepositoryOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateRepositoryCallable = + callableFactory.createUnaryCallable( + updateRepositoryTransportSettings, settings.updateRepositorySettings(), clientContext); + this.deleteRepositoryCallable = + callableFactory.createUnaryCallable( + deleteRepositoryTransportSettings, settings.deleteRepositorySettings(), clientContext); + this.deleteRepositoryOperationCallable = + callableFactory.createOperationCallable( + deleteRepositoryTransportSettings, + settings.deleteRepositoryOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listPackagesCallable = + callableFactory.createUnaryCallable( + listPackagesTransportSettings, settings.listPackagesSettings(), clientContext); + this.listPackagesPagedCallable = + callableFactory.createPagedCallable( + listPackagesTransportSettings, settings.listPackagesSettings(), clientContext); + this.getPackageCallable = + callableFactory.createUnaryCallable( + getPackageTransportSettings, settings.getPackageSettings(), clientContext); + this.deletePackageCallable = + callableFactory.createUnaryCallable( + deletePackageTransportSettings, settings.deletePackageSettings(), clientContext); + this.deletePackageOperationCallable = + callableFactory.createOperationCallable( + deletePackageTransportSettings, + settings.deletePackageOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listVersionsCallable = + callableFactory.createUnaryCallable( + listVersionsTransportSettings, settings.listVersionsSettings(), clientContext); + this.listVersionsPagedCallable = + callableFactory.createPagedCallable( + listVersionsTransportSettings, settings.listVersionsSettings(), clientContext); + this.getVersionCallable = + callableFactory.createUnaryCallable( + getVersionTransportSettings, settings.getVersionSettings(), clientContext); + this.deleteVersionCallable = + callableFactory.createUnaryCallable( + deleteVersionTransportSettings, settings.deleteVersionSettings(), clientContext); + this.deleteVersionOperationCallable = + callableFactory.createOperationCallable( + deleteVersionTransportSettings, + settings.deleteVersionOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listFilesCallable = + callableFactory.createUnaryCallable( + listFilesTransportSettings, settings.listFilesSettings(), clientContext); + this.listFilesPagedCallable = + callableFactory.createPagedCallable( + listFilesTransportSettings, settings.listFilesSettings(), clientContext); + this.getFileCallable = + callableFactory.createUnaryCallable( + getFileTransportSettings, settings.getFileSettings(), clientContext); + this.listTagsCallable = + callableFactory.createUnaryCallable( + listTagsTransportSettings, settings.listTagsSettings(), clientContext); + this.listTagsPagedCallable = + callableFactory.createPagedCallable( + listTagsTransportSettings, settings.listTagsSettings(), clientContext); + this.getTagCallable = + callableFactory.createUnaryCallable( + getTagTransportSettings, settings.getTagSettings(), clientContext); + this.createTagCallable = + callableFactory.createUnaryCallable( + createTagTransportSettings, settings.createTagSettings(), clientContext); + this.updateTagCallable = + callableFactory.createUnaryCallable( + updateTagTransportSettings, settings.updateTagSettings(), clientContext); + this.deleteTagCallable = + callableFactory.createUnaryCallable( + deleteTagTransportSettings, settings.deleteTagSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + this.getProjectSettingsCallable = + callableFactory.createUnaryCallable( + getProjectSettingsTransportSettings, + settings.getProjectSettingsSettings(), + clientContext); + this.updateProjectSettingsCallable = + callableFactory.createUnaryCallable( + updateProjectSettingsTransportSettings, + settings.updateProjectSettingsSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(importAptArtifactsMethodDescriptor); + methodDescriptors.add(importYumArtifactsMethodDescriptor); + methodDescriptors.add(listRepositoriesMethodDescriptor); + methodDescriptors.add(getRepositoryMethodDescriptor); + methodDescriptors.add(createRepositoryMethodDescriptor); + methodDescriptors.add(updateRepositoryMethodDescriptor); + methodDescriptors.add(deleteRepositoryMethodDescriptor); + methodDescriptors.add(listPackagesMethodDescriptor); + methodDescriptors.add(getPackageMethodDescriptor); + methodDescriptors.add(deletePackageMethodDescriptor); + methodDescriptors.add(listVersionsMethodDescriptor); + methodDescriptors.add(getVersionMethodDescriptor); + methodDescriptors.add(deleteVersionMethodDescriptor); + methodDescriptors.add(listFilesMethodDescriptor); + methodDescriptors.add(getFileMethodDescriptor); + methodDescriptors.add(listTagsMethodDescriptor); + methodDescriptors.add(getTagMethodDescriptor); + methodDescriptors.add(createTagMethodDescriptor); + methodDescriptors.add(updateTagMethodDescriptor); + methodDescriptors.add(deleteTagMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + methodDescriptors.add(getProjectSettingsMethodDescriptor); + methodDescriptors.add(updateProjectSettingsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable importAptArtifactsCallable() { + return importAptArtifactsCallable; + } + + @Override + public OperationCallable< + ImportAptArtifactsRequest, ImportAptArtifactsResponse, ImportAptArtifactsMetadata> + importAptArtifactsOperationCallable() { + return importAptArtifactsOperationCallable; + } + + @Override + public UnaryCallable importYumArtifactsCallable() { + return importYumArtifactsCallable; + } + + @Override + public OperationCallable< + ImportYumArtifactsRequest, ImportYumArtifactsResponse, ImportYumArtifactsMetadata> + importYumArtifactsOperationCallable() { + return importYumArtifactsOperationCallable; + } + + @Override + public UnaryCallable + listRepositoriesCallable() { + return listRepositoriesCallable; + } + + @Override + public UnaryCallable + listRepositoriesPagedCallable() { + return listRepositoriesPagedCallable; + } + + @Override + public UnaryCallable getRepositoryCallable() { + return getRepositoryCallable; + } + + @Override + public UnaryCallable createRepositoryCallable() { + return createRepositoryCallable; + } + + @Override + public OperationCallable + createRepositoryOperationCallable() { + return createRepositoryOperationCallable; + } + + @Override + public UnaryCallable updateRepositoryCallable() { + return updateRepositoryCallable; + } + + @Override + public UnaryCallable deleteRepositoryCallable() { + return deleteRepositoryCallable; + } + + @Override + public OperationCallable + deleteRepositoryOperationCallable() { + return deleteRepositoryOperationCallable; + } + + @Override + public UnaryCallable listPackagesCallable() { + return listPackagesCallable; + } + + @Override + public UnaryCallable listPackagesPagedCallable() { + return listPackagesPagedCallable; + } + + @Override + public UnaryCallable getPackageCallable() { + return getPackageCallable; + } + + @Override + public UnaryCallable deletePackageCallable() { + return deletePackageCallable; + } + + @Override + public OperationCallable + deletePackageOperationCallable() { + return deletePackageOperationCallable; + } + + @Override + public UnaryCallable listVersionsCallable() { + return listVersionsCallable; + } + + @Override + public UnaryCallable listVersionsPagedCallable() { + return listVersionsPagedCallable; + } + + @Override + public UnaryCallable getVersionCallable() { + return getVersionCallable; + } + + @Override + public UnaryCallable deleteVersionCallable() { + return deleteVersionCallable; + } + + @Override + public OperationCallable + deleteVersionOperationCallable() { + return deleteVersionOperationCallable; + } + + @Override + public UnaryCallable listFilesCallable() { + return listFilesCallable; + } + + @Override + public UnaryCallable listFilesPagedCallable() { + return listFilesPagedCallable; + } + + @Override + public UnaryCallable getFileCallable() { + return getFileCallable; + } + + @Override + public UnaryCallable listTagsCallable() { + return listTagsCallable; + } + + @Override + public UnaryCallable listTagsPagedCallable() { + return listTagsPagedCallable; + } + + @Override + public UnaryCallable getTagCallable() { + return getTagCallable; + } + + @Override + public UnaryCallable createTagCallable() { + return createTagCallable; + } + + @Override + public UnaryCallable updateTagCallable() { + return updateTagCallable; + } + + @Override + public UnaryCallable deleteTagCallable() { + return deleteTagCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public UnaryCallable getProjectSettingsCallable() { + return getProjectSettingsCallable; + } + + @Override + public UnaryCallable + updateProjectSettingsCallable() { + return updateProjectSettingsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientHttpJsonTest.java b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientHttpJsonTest.java new file mode 100644 index 00000000..985a2746 --- /dev/null +++ b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientHttpJsonTest.java @@ -0,0 +1,1786 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.artifactregistry.v1; + +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListDockerImagesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListFilesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListPackagesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListRepositoriesPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListTagsPagedResponse; +import static com.google.devtools.artifactregistry.v1.ArtifactRegistryClient.ListVersionsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.common.collect.Lists; +import com.google.devtools.artifactregistry.v1.stub.HttpJsonArtifactRegistryStub; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Struct; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class ArtifactRegistryClientHttpJsonTest { + private static MockHttpService mockService; + private static ArtifactRegistryClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonArtifactRegistryStub.getMethodDescriptors(), + ArtifactRegistrySettings.getDefaultEndpoint()); + ArtifactRegistrySettings settings = + ArtifactRegistrySettings.newHttpJsonBuilder() + .setTransportChannelProvider( + ArtifactRegistrySettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ArtifactRegistryClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listDockerImagesTest() throws Exception { + DockerImage responsesElement = DockerImage.newBuilder().build(); + ListDockerImagesResponse expectedResponse = + ListDockerImagesResponse.newBuilder() + .setNextPageToken("") + .addAllDockerImages(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + + ListDockerImagesPagedResponse pagedListResponse = client.listDockerImages(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getDockerImagesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listDockerImagesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + client.listDockerImages(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getDockerImageTest() throws Exception { + DockerImage expectedResponse = + DockerImage.newBuilder() + .setName( + DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") + .toString()) + .setUri("uri116076") + .addAllTags(new ArrayList()) + .setImageSizeBytes(837030929) + .setUploadTime(Timestamp.newBuilder().build()) + .setMediaType("mediaType2140463422") + .setBuildTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + DockerImageName name = + DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]"); + + DockerImage actualResponse = client.getDockerImage(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getDockerImageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DockerImageName name = + DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]"); + client.getDockerImage(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getDockerImageTest2() throws Exception { + DockerImage expectedResponse = + DockerImage.newBuilder() + .setName( + DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") + .toString()) + .setUri("uri116076") + .addAllTags(new ArrayList()) + .setImageSizeBytes(837030929) + .setUploadTime(Timestamp.newBuilder().build()) + .setMediaType("mediaType2140463422") + .setBuildTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-1270/locations/location-1270/repositories/repositorie-1270/dockerImages/dockerImage-1270"; + + DockerImage actualResponse = client.getDockerImage(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getDockerImageExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-1270/locations/location-1270/repositories/repositorie-1270/dockerImages/dockerImage-1270"; + client.getDockerImage(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void importAptArtifactsTest() throws Exception { + ImportAptArtifactsResponse expectedResponse = + ImportAptArtifactsResponse.newBuilder() + .addAllAptArtifacts(new ArrayList()) + .addAllErrors(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importAptArtifactsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ImportAptArtifactsRequest request = + ImportAptArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + + ImportAptArtifactsResponse actualResponse = client.importAptArtifactsAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void importAptArtifactsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportAptArtifactsRequest request = + ImportAptArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + client.importAptArtifactsAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importYumArtifactsTest() throws Exception { + ImportYumArtifactsResponse expectedResponse = + ImportYumArtifactsResponse.newBuilder() + .addAllYumArtifacts(new ArrayList()) + .addAllErrors(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importYumArtifactsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ImportYumArtifactsRequest request = + ImportYumArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + + ImportYumArtifactsResponse actualResponse = client.importYumArtifactsAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void importYumArtifactsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportYumArtifactsRequest request = + ImportYumArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + client.importYumArtifactsAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listRepositoriesTest() throws Exception { + Repository responsesElement = Repository.newBuilder().build(); + ListRepositoriesResponse expectedResponse = + ListRepositoriesResponse.newBuilder() + .setNextPageToken("") + .addAllRepositories(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListRepositoriesPagedResponse pagedListResponse = client.listRepositories(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRepositoriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRepositoriesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listRepositories(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRepositoriesTest2() throws Exception { + Repository responsesElement = Repository.newBuilder().build(); + ListRepositoriesResponse expectedResponse = + ListRepositoriesResponse.newBuilder() + .setNextPageToken("") + .addAllRepositories(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListRepositoriesPagedResponse pagedListResponse = client.listRepositories(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRepositoriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRepositoriesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listRepositories(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRepositoryTest() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + mockService.addResponse(expectedResponse); + + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + + Repository actualResponse = client.getRepository(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + client.getRepository(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRepositoryTest2() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + + Repository actualResponse = client.getRepository(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRepositoryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + client.getRepository(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createRepositoryTest() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + + Repository actualResponse = + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createRepositoryTest2() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + + Repository actualResponse = + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createRepositoryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateRepositoryTest() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + mockService.addResponse(expectedResponse); + + Repository repository = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Repository actualResponse = client.updateRepository(repository, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Repository repository = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateRepository(repository, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRepositoryTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + + client.deleteRepositoryAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + client.deleteRepositoryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRepositoryTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + + client.deleteRepositoryAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRepositoryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + client.deleteRepositoryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listPackagesTest() throws Exception { + Package responsesElement = Package.newBuilder().build(); + ListPackagesResponse expectedResponse = + ListPackagesResponse.newBuilder() + .setNextPageToken("") + .addAllPackages(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + + ListPackagesPagedResponse pagedListResponse = client.listPackages(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getPackagesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listPackagesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + client.listPackages(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getPackageTest() throws Exception { + Package expectedResponse = + Package.newBuilder() + .setName("name3373707") + .setDisplayName("displayName1714148973") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + + Package actualResponse = client.getPackage(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getPackageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + client.getPackage(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deletePackageTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deletePackageTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + + client.deletePackageAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deletePackageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + client.deletePackageAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listVersionsTest() throws Exception { + Version responsesElement = Version.newBuilder().build(); + ListVersionsResponse expectedResponse = + ListVersionsResponse.newBuilder() + .setNextPageToken("") + .addAllVersions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + + ListVersionsPagedResponse pagedListResponse = client.listVersions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listVersionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + client.listVersions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getVersionTest() throws Exception { + Version expectedResponse = + Version.newBuilder() + .setName("name3373707") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .addAllRelatedTags(new ArrayList()) + .setMetadata(Struct.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + + Version actualResponse = client.getVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + client.getVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteVersionTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteVersionTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + + client.deleteVersionAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + client.deleteVersionAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listFilesTest() throws Exception { + File responsesElement = File.newBuilder().build(); + ListFilesResponse expectedResponse = + ListFilesResponse.newBuilder() + .setNextPageToken("") + .addAllFiles(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + + ListFilesPagedResponse pagedListResponse = client.listFiles(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getFilesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listFilesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + client.listFiles(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getFileTest() throws Exception { + File expectedResponse = + File.newBuilder() + .setName("name3373707") + .setSizeBytes(-1796325715) + .addAllHashes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setOwner("owner106164915") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-3631/locations/location-3631/repositories/repositorie-3631/files/file-3631"; + + File actualResponse = client.getFile(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getFileExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3631/locations/location-3631/repositories/repositorie-3631/files/file-3631"; + client.getFile(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTagsTest() throws Exception { + Tag responsesElement = Tag.newBuilder().build(); + ListTagsResponse expectedResponse = + ListTagsResponse.newBuilder() + .setNextPageToken("") + .addAllTags(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + + ListTagsPagedResponse pagedListResponse = client.listTags(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTagsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listTagsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + client.listTags(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTagTest() throws Exception { + Tag expectedResponse = + Tag.newBuilder().setName("name3373707").setVersion("version351608024").build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + + Tag actualResponse = client.getTag(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + client.getTag(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTagTest() throws Exception { + Tag expectedResponse = + Tag.newBuilder().setName("name3373707").setVersion("version351608024").build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + Tag tag = Tag.newBuilder().build(); + String tagId = "tagId110119509"; + + Tag actualResponse = client.createTag(parent, tag, tagId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + Tag tag = Tag.newBuilder().build(); + String tagId = "tagId110119509"; + client.createTag(parent, tag, tagId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateTagTest() throws Exception { + Tag expectedResponse = + Tag.newBuilder().setName("name3373707").setVersion("version351608024").build(); + mockService.addResponse(expectedResponse); + + Tag tag = + Tag.newBuilder() + .setName( + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748") + .setVersion("version351608024") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Tag actualResponse = client.updateTag(tag, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Tag tag = + Tag.newBuilder() + .setName( + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748") + .setVersion("version351608024") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateTag(tag, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTagTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + + client.deleteTag(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + client.deleteTag(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getProjectSettingsTest() throws Exception { + ProjectSettings expectedResponse = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectSettingsName name = ProjectSettingsName.of("[PROJECT]"); + + ProjectSettings actualResponse = client.getProjectSettings(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getProjectSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectSettingsName name = ProjectSettingsName.of("[PROJECT]"); + client.getProjectSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getProjectSettingsTest2() throws Exception { + ProjectSettings expectedResponse = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9549/projectSettings"; + + ProjectSettings actualResponse = client.getProjectSettings(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getProjectSettingsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9549/projectSettings"; + client.getProjectSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateProjectSettingsTest() throws Exception { + ProjectSettings expectedResponse = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectSettings projectSettings = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + ProjectSettings actualResponse = client.updateProjectSettings(projectSettings, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateProjectSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectSettings projectSettings = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateProjectSettings(projectSettings, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientTest.java b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientTest.java index 6276ac70..5d8f4c2d 100644 --- a/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientTest.java +++ b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1/ArtifactRegistryClientTest.java @@ -1311,9 +1311,7 @@ public void setIamPolicyTest() throws Exception { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() - .setResource( - DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - .toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setPolicy(Policy.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); @@ -1342,9 +1340,7 @@ public void setIamPolicyExceptionTest() throws Exception { try { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() - .setResource( - DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - .toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setPolicy(Policy.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); @@ -1368,9 +1364,7 @@ public void getIamPolicyTest() throws Exception { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() - .setResource( - DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - .toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setOptions(GetPolicyOptions.newBuilder().build()) .build(); @@ -1397,9 +1391,7 @@ public void getIamPolicyExceptionTest() throws Exception { try { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() - .setResource( - DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - .toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setOptions(GetPolicyOptions.newBuilder().build()) .build(); client.getIamPolicy(request); @@ -1417,9 +1409,7 @@ public void testIamPermissionsTest() throws Exception { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() - .setResource( - DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - .toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .addAllPermissions(new ArrayList()) .build(); @@ -1446,9 +1436,7 @@ public void testIamPermissionsExceptionTest() throws Exception { try { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() - .setResource( - DockerImageName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]", "[DOCKER_IMAGE]") - .toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .addAllPermissions(new ArrayList()) .build(); client.testIamPermissions(request); diff --git a/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientHttpJsonTest.java b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientHttpJsonTest.java new file mode 100644 index 00000000..194736b2 --- /dev/null +++ b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientHttpJsonTest.java @@ -0,0 +1,1627 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.artifactregistry.v1beta2; + +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListFilesPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListPackagesPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListRepositoriesPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListTagsPagedResponse; +import static com.google.devtools.artifactregistry.v1beta2.ArtifactRegistryClient.ListVersionsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.common.collect.Lists; +import com.google.devtools.artifactregistry.v1beta2.stub.HttpJsonArtifactRegistryStub; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Struct; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class ArtifactRegistryClientHttpJsonTest { + private static MockHttpService mockService; + private static ArtifactRegistryClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonArtifactRegistryStub.getMethodDescriptors(), + ArtifactRegistrySettings.getDefaultEndpoint()); + ArtifactRegistrySettings settings = + ArtifactRegistrySettings.newHttpJsonBuilder() + .setTransportChannelProvider( + ArtifactRegistrySettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ArtifactRegistryClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void importAptArtifactsTest() throws Exception { + ImportAptArtifactsResponse expectedResponse = + ImportAptArtifactsResponse.newBuilder() + .addAllAptArtifacts(new ArrayList()) + .addAllErrors(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importAptArtifactsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ImportAptArtifactsRequest request = + ImportAptArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + + ImportAptArtifactsResponse actualResponse = client.importAptArtifactsAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void importAptArtifactsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportAptArtifactsRequest request = + ImportAptArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + client.importAptArtifactsAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importYumArtifactsTest() throws Exception { + ImportYumArtifactsResponse expectedResponse = + ImportYumArtifactsResponse.newBuilder() + .addAllYumArtifacts(new ArrayList()) + .addAllErrors(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importYumArtifactsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ImportYumArtifactsRequest request = + ImportYumArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + + ImportYumArtifactsResponse actualResponse = client.importYumArtifactsAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void importYumArtifactsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportYumArtifactsRequest request = + ImportYumArtifactsRequest.newBuilder() + .setParent( + "projects/project-9015/locations/location-9015/repositories/repositorie-9015") + .build(); + client.importYumArtifactsAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listRepositoriesTest() throws Exception { + Repository responsesElement = Repository.newBuilder().build(); + ListRepositoriesResponse expectedResponse = + ListRepositoriesResponse.newBuilder() + .setNextPageToken("") + .addAllRepositories(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListRepositoriesPagedResponse pagedListResponse = client.listRepositories(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRepositoriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRepositoriesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listRepositories(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listRepositoriesTest2() throws Exception { + Repository responsesElement = Repository.newBuilder().build(); + ListRepositoriesResponse expectedResponse = + ListRepositoriesResponse.newBuilder() + .setNextPageToken("") + .addAllRepositories(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListRepositoriesPagedResponse pagedListResponse = client.listRepositories(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getRepositoriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listRepositoriesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listRepositories(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRepositoryTest() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + mockService.addResponse(expectedResponse); + + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + + Repository actualResponse = client.getRepository(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + client.getRepository(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getRepositoryTest2() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + + Repository actualResponse = client.getRepository(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getRepositoryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + client.getRepository(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createRepositoryTest() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + + Repository actualResponse = + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createRepositoryTest2() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + + Repository actualResponse = + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createRepositoryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Repository repository = Repository.newBuilder().build(); + String repositoryId = "repositoryId2113747461"; + client.createRepositoryAsync(parent, repository, repositoryId).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateRepositoryTest() throws Exception { + Repository expectedResponse = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + mockService.addResponse(expectedResponse); + + Repository repository = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Repository actualResponse = client.updateRepository(repository, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Repository repository = + Repository.newBuilder() + .setName(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setDescription("description-1724546052") + .putAllLabels(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setKmsKeyName("kmsKeyName412586233") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateRepository(repository, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteRepositoryTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + + client.deleteRepositoryAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRepositoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RepositoryName name = RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]"); + client.deleteRepositoryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteRepositoryTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteRepositoryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + + client.deleteRepositoryAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteRepositoryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4840/locations/location-4840/repositories/repositorie-4840"; + client.deleteRepositoryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listPackagesTest() throws Exception { + Package responsesElement = Package.newBuilder().build(); + ListPackagesResponse expectedResponse = + ListPackagesResponse.newBuilder() + .setNextPageToken("") + .addAllPackages(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + + ListPackagesPagedResponse pagedListResponse = client.listPackages(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getPackagesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listPackagesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + client.listPackages(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getPackageTest() throws Exception { + Package expectedResponse = + Package.newBuilder() + .setName("name3373707") + .setDisplayName("displayName1714148973") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + + Package actualResponse = client.getPackage(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getPackageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + client.getPackage(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deletePackageTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deletePackageTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + + client.deletePackageAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deletePackageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-639/locations/location-639/repositories/repositorie-639/packages/package-639"; + client.deletePackageAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listVersionsTest() throws Exception { + Version responsesElement = Version.newBuilder().build(); + ListVersionsResponse expectedResponse = + ListVersionsResponse.newBuilder() + .setNextPageToken("") + .addAllVersions(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + + ListVersionsPagedResponse pagedListResponse = client.listVersions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listVersionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + client.listVersions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getVersionTest() throws Exception { + Version expectedResponse = + Version.newBuilder() + .setName("name3373707") + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .addAllRelatedTags(new ArrayList()) + .setMetadata(Struct.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + + Version actualResponse = client.getVersion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + client.getVersion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteVersionTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteVersionTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + + client.deleteVersionAsync(name).get(); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteVersionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9642/locations/location-9642/repositories/repositorie-9642/packages/package-9642/versions/version-9642"; + client.deleteVersionAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listFilesTest() throws Exception { + File responsesElement = File.newBuilder().build(); + ListFilesResponse expectedResponse = + ListFilesResponse.newBuilder() + .setNextPageToken("") + .addAllFiles(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + + ListFilesPagedResponse pagedListResponse = client.listFiles(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getFilesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listFilesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9015/locations/location-9015/repositories/repositorie-9015"; + client.listFiles(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getFileTest() throws Exception { + File expectedResponse = + File.newBuilder() + .setName("name3373707") + .setSizeBytes(-1796325715) + .addAllHashes(new ArrayList()) + .setCreateTime(Timestamp.newBuilder().build()) + .setUpdateTime(Timestamp.newBuilder().build()) + .setOwner("owner106164915") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-3631/locations/location-3631/repositories/repositorie-3631/files/file-3631"; + + File actualResponse = client.getFile(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getFileExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3631/locations/location-3631/repositories/repositorie-3631/files/file-3631"; + client.getFile(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTagsTest() throws Exception { + Tag responsesElement = Tag.newBuilder().build(); + ListTagsResponse expectedResponse = + ListTagsResponse.newBuilder() + .setNextPageToken("") + .addAllTags(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + + ListTagsPagedResponse pagedListResponse = client.listTags(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTagsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listTagsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + client.listTags(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTagTest() throws Exception { + Tag expectedResponse = + Tag.newBuilder().setName("name3373707").setVersion("version351608024").build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + + Tag actualResponse = client.getTag(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + client.getTag(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTagTest() throws Exception { + Tag expectedResponse = + Tag.newBuilder().setName("name3373707").setVersion("version351608024").build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + Tag tag = Tag.newBuilder().build(); + String tagId = "tagId110119509"; + + Tag actualResponse = client.createTag(parent, tag, tagId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-5394/locations/location-5394/repositories/repositorie-5394/packages/package-5394"; + Tag tag = Tag.newBuilder().build(); + String tagId = "tagId110119509"; + client.createTag(parent, tag, tagId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateTagTest() throws Exception { + Tag expectedResponse = + Tag.newBuilder().setName("name3373707").setVersion("version351608024").build(); + mockService.addResponse(expectedResponse); + + Tag tag = + Tag.newBuilder() + .setName( + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748") + .setVersion("version351608024") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Tag actualResponse = client.updateTag(tag, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Tag tag = + Tag.newBuilder() + .setName( + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748") + .setVersion("version351608024") + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateTag(tag, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTagTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + + client.deleteTag(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTagExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-5748/locations/location-5748/repositories/repositorie-5748/packages/package-5748/tags/tag-5748"; + client.deleteTag(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getProjectSettingsTest() throws Exception { + ProjectSettings expectedResponse = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectSettingsName name = ProjectSettingsName.of("[PROJECT]"); + + ProjectSettings actualResponse = client.getProjectSettings(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getProjectSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectSettingsName name = ProjectSettingsName.of("[PROJECT]"); + client.getProjectSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getProjectSettingsTest2() throws Exception { + ProjectSettings expectedResponse = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9549/projectSettings"; + + ProjectSettings actualResponse = client.getProjectSettings(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getProjectSettingsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9549/projectSettings"; + client.getProjectSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateProjectSettingsTest() throws Exception { + ProjectSettings expectedResponse = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectSettings projectSettings = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + ProjectSettings actualResponse = client.updateProjectSettings(projectSettings, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateProjectSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectSettings projectSettings = + ProjectSettings.newBuilder() + .setName(ProjectSettingsName.of("[PROJECT]").toString()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateProjectSettings(projectSettings, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientTest.java b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientTest.java index f2eb4265..ebee0db6 100644 --- a/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientTest.java +++ b/google-cloud-artifact-registry/src/test/java/com/google/devtools/artifactregistry/v1beta2/ArtifactRegistryClientTest.java @@ -1172,7 +1172,7 @@ public void setIamPolicyTest() throws Exception { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() - .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setPolicy(Policy.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); @@ -1201,7 +1201,7 @@ public void setIamPolicyExceptionTest() throws Exception { try { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() - .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setPolicy(Policy.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); @@ -1225,7 +1225,7 @@ public void getIamPolicyTest() throws Exception { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() - .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setOptions(GetPolicyOptions.newBuilder().build()) .build(); @@ -1252,7 +1252,7 @@ public void getIamPolicyExceptionTest() throws Exception { try { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() - .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .setOptions(GetPolicyOptions.newBuilder().build()) .build(); client.getIamPolicy(request); @@ -1270,7 +1270,7 @@ public void testIamPermissionsTest() throws Exception { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() - .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .addAllPermissions(new ArrayList()) .build(); @@ -1297,7 +1297,7 @@ public void testIamPermissionsExceptionTest() throws Exception { try { TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder() - .setResource(ProjectSettingsName.of("[PROJECT]").toString()) + .setResource(RepositoryName.of("[PROJECT]", "[LOCATION]", "[REPOSITORY]").toString()) .addAllPermissions(new ArrayList()) .build(); client.testIamPermissions(request);