From 8eb254902dcf6fc549407db4d934fabbe4b329e6 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 15:08:33 +0000 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#754) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 --- .../google-cloud-accessapproval/pom.xml | 16 + .../v1/AccessApprovalAdminClient.java | 15 + .../v1/AccessApprovalAdminSettings.java | 23 +- .../v1/stub/AccessApprovalStubSettings.java | 53 +- ...HttpJsonAccessApprovalCallableFactory.java | 105 +++ .../v1/stub/HttpJsonAccessApprovalStub.java | 708 ++++++++++++++ ...AccessApprovalAdminClientHttpJsonTest.java | 874 ++++++++++++++++++ .../SyncCreateSetCredentialsProvider1.java | 41 + 8 files changed, 1830 insertions(+), 5 deletions(-) create mode 100644 java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalCallableFactory.java create mode 100644 java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalStub.java create mode 100644 java-accessapproval/google-cloud-accessapproval/src/test/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClientHttpJsonTest.java create mode 100644 java-accessapproval/samples/snippets/generated/com/google/cloud/accessapproval/v1/accessapprovaladminclient/create/SyncCreateSetCredentialsProvider1.java diff --git a/java-accessapproval/google-cloud-accessapproval/pom.xml b/java-accessapproval/google-cloud-accessapproval/pom.xml index 722da56b18e4..7c2a584a9b5e 100644 --- a/java-accessapproval/google-cloud-accessapproval/pom.xml +++ b/java-accessapproval/google-cloud-accessapproval/pom.xml @@ -57,6 +57,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -74,12 +78,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/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClient.java b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClient.java index 48eb1ca1aa54..88dbfd23e7bb 100644 --- a/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClient.java +++ b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClient.java @@ -130,6 +130,21 @@ * AccessApprovalAdminClient.create(accessApprovalAdminSettings); * } * + *

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.
+ * AccessApprovalAdminSettings accessApprovalAdminSettings =
+ *     AccessApprovalAdminSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AccessApprovalAdminSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AccessApprovalAdminClient accessApprovalAdminClient =
+ *     AccessApprovalAdminClient.create(accessApprovalAdminSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminSettings.java b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminSettings.java index 64a5c986c79a..8bd2bb08bfb7 100644 --- a/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminSettings.java +++ b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminSettings.java @@ -23,6 +23,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; @@ -157,11 +158,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AccessApprovalStubSettings.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 AccessApprovalStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AccessApprovalStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AccessApprovalStubSettings.defaultTransportChannelProvider(); } @@ -171,11 +179,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AccessApprovalStubSettings.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); @@ -213,6 +227,11 @@ private static Builder createDefault() { return new Builder(AccessApprovalStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AccessApprovalStubSettings.newHttpJsonBuilder()); + } + public AccessApprovalStubSettings.Builder getStubSettingsBuilder() { return ((AccessApprovalStubSettings.Builder) getStubSettings()); } diff --git a/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/AccessApprovalStubSettings.java b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/AccessApprovalStubSettings.java index 101fabeb5bd6..c88f92a815c1 100644 --- a/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/AccessApprovalStubSettings.java +++ b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/AccessApprovalStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +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.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -256,6 +259,11 @@ public AccessApprovalStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAccessApprovalStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAccessApprovalStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -288,18 +296,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(AccessApprovalStubSettings.class)) @@ -307,11 +322,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(AccessApprovalStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AccessApprovalStubSettings.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); @@ -484,6 +518,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 .listApprovalRequestsSettings() diff --git a/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalCallableFactory.java b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalCallableFactory.java new file mode 100644 index 000000000000..e0ab85278cff --- /dev/null +++ b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalCallableFactory.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.cloud.accessapproval.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 AccessApproval service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonAccessApprovalCallableFactory + 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/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalStub.java b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalStub.java new file mode 100644 index 000000000000..c1e963a0a36c --- /dev/null +++ b/java-accessapproval/google-cloud-accessapproval/src/main/java/com/google/cloud/accessapproval/v1/stub/HttpJsonAccessApprovalStub.java @@ -0,0 +1,708 @@ +/* + * 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.cloud.accessapproval.v1.stub; + +import static com.google.cloud.accessapproval.v1.AccessApprovalAdminClient.ListApprovalRequestsPagedResponse; + +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.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.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.accessapproval.v1.AccessApprovalServiceAccount; +import com.google.cloud.accessapproval.v1.AccessApprovalSettings; +import com.google.cloud.accessapproval.v1.ApprovalRequest; +import com.google.cloud.accessapproval.v1.ApproveApprovalRequestMessage; +import com.google.cloud.accessapproval.v1.DeleteAccessApprovalSettingsMessage; +import com.google.cloud.accessapproval.v1.DismissApprovalRequestMessage; +import com.google.cloud.accessapproval.v1.GetAccessApprovalServiceAccountMessage; +import com.google.cloud.accessapproval.v1.GetAccessApprovalSettingsMessage; +import com.google.cloud.accessapproval.v1.GetApprovalRequestMessage; +import com.google.cloud.accessapproval.v1.InvalidateApprovalRequestMessage; +import com.google.cloud.accessapproval.v1.ListApprovalRequestsMessage; +import com.google.cloud.accessapproval.v1.ListApprovalRequestsResponse; +import com.google.cloud.accessapproval.v1.UpdateAccessApprovalSettingsMessage; +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 AccessApproval service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonAccessApprovalStub extends AccessApprovalStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor< + ListApprovalRequestsMessage, ListApprovalRequestsResponse> + listApprovalRequestsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/ListApprovalRequests") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=projects/*}/approvalRequests", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v1/{parent=folders/*}/approvalRequests", + "/v1/{parent=organizations/*}/approvalRequests") + .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(ListApprovalRequestsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getApprovalRequestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.accessapproval.v1.AccessApproval/GetApprovalRequest") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/approvalRequests/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/approvalRequests/*}", + "/v1/{name=organizations/*/approvalRequests/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ApprovalRequest.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + approveApprovalRequestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/ApproveApprovalRequest") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/approvalRequests/*}:approve", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/approvalRequests/*}:approve", + "/v1/{name=organizations/*/approvalRequests/*}:approve") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ApprovalRequest.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + dismissApprovalRequestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/DismissApprovalRequest") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/approvalRequests/*}:dismiss", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/approvalRequests/*}:dismiss", + "/v1/{name=organizations/*/approvalRequests/*}:dismiss") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ApprovalRequest.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + invalidateApprovalRequestMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/InvalidateApprovalRequest") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/approvalRequests/*}:invalidate", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/approvalRequests/*}:invalidate", + "/v1/{name=organizations/*/approvalRequests/*}:invalidate") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ApprovalRequest.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getAccessApprovalSettingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/GetAccessApprovalSettings") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/accessApprovalSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/accessApprovalSettings}", + "/v1/{name=organizations/*/accessApprovalSettings}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AccessApprovalSettings.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + UpdateAccessApprovalSettingsMessage, AccessApprovalSettings> + updateAccessApprovalSettingsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/UpdateAccessApprovalSettings") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{settings.name=projects/*/accessApprovalSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "settings.name", request.getSettings().getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{settings.name=folders/*/accessApprovalSettings}", + "/v1/{settings.name=organizations/*/accessApprovalSettings}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("settings", request.getSettings())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AccessApprovalSettings.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteAccessApprovalSettingsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/DeleteAccessApprovalSettings") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/accessApprovalSettings}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/accessApprovalSettings}", + "/v1/{name=organizations/*/accessApprovalSettings}") + .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< + GetAccessApprovalServiceAccountMessage, AccessApprovalServiceAccount> + getAccessApprovalServiceAccountMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.accessapproval.v1.AccessApproval/GetAccessApprovalServiceAccount") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*/serviceAccount}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v1/{name=folders/*/serviceAccount}", + "/v1/{name=organizations/*/serviceAccount}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AccessApprovalServiceAccount.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + listApprovalRequestsCallable; + private final UnaryCallable + listApprovalRequestsPagedCallable; + private final UnaryCallable + getApprovalRequestCallable; + private final UnaryCallable + approveApprovalRequestCallable; + private final UnaryCallable + dismissApprovalRequestCallable; + private final UnaryCallable + invalidateApprovalRequestCallable; + private final UnaryCallable + getAccessApprovalSettingsCallable; + private final UnaryCallable + updateAccessApprovalSettingsCallable; + private final UnaryCallable + deleteAccessApprovalSettingsCallable; + private final UnaryCallable + getAccessApprovalServiceAccountCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAccessApprovalStub create(AccessApprovalStubSettings settings) + throws IOException { + return new HttpJsonAccessApprovalStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAccessApprovalStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAccessApprovalStub( + AccessApprovalStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAccessApprovalStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAccessApprovalStub( + AccessApprovalStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAccessApprovalStub, 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 HttpJsonAccessApprovalStub( + AccessApprovalStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonAccessApprovalCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAccessApprovalStub, 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 HttpJsonAccessApprovalStub( + AccessApprovalStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + listApprovalRequestsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listApprovalRequestsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getApprovalRequestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getApprovalRequestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + approveApprovalRequestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(approveApprovalRequestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + dismissApprovalRequestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(dismissApprovalRequestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + invalidateApprovalRequestTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(invalidateApprovalRequestMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getAccessApprovalSettingsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(getAccessApprovalSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateAccessApprovalSettingsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(updateAccessApprovalSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteAccessApprovalSettingsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteAccessApprovalSettingsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getAccessApprovalServiceAccountTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(getAccessApprovalServiceAccountMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listApprovalRequestsCallable = + callableFactory.createUnaryCallable( + listApprovalRequestsTransportSettings, + settings.listApprovalRequestsSettings(), + clientContext); + this.listApprovalRequestsPagedCallable = + callableFactory.createPagedCallable( + listApprovalRequestsTransportSettings, + settings.listApprovalRequestsSettings(), + clientContext); + this.getApprovalRequestCallable = + callableFactory.createUnaryCallable( + getApprovalRequestTransportSettings, + settings.getApprovalRequestSettings(), + clientContext); + this.approveApprovalRequestCallable = + callableFactory.createUnaryCallable( + approveApprovalRequestTransportSettings, + settings.approveApprovalRequestSettings(), + clientContext); + this.dismissApprovalRequestCallable = + callableFactory.createUnaryCallable( + dismissApprovalRequestTransportSettings, + settings.dismissApprovalRequestSettings(), + clientContext); + this.invalidateApprovalRequestCallable = + callableFactory.createUnaryCallable( + invalidateApprovalRequestTransportSettings, + settings.invalidateApprovalRequestSettings(), + clientContext); + this.getAccessApprovalSettingsCallable = + callableFactory.createUnaryCallable( + getAccessApprovalSettingsTransportSettings, + settings.getAccessApprovalSettingsSettings(), + clientContext); + this.updateAccessApprovalSettingsCallable = + callableFactory.createUnaryCallable( + updateAccessApprovalSettingsTransportSettings, + settings.updateAccessApprovalSettingsSettings(), + clientContext); + this.deleteAccessApprovalSettingsCallable = + callableFactory.createUnaryCallable( + deleteAccessApprovalSettingsTransportSettings, + settings.deleteAccessApprovalSettingsSettings(), + clientContext); + this.getAccessApprovalServiceAccountCallable = + callableFactory.createUnaryCallable( + getAccessApprovalServiceAccountTransportSettings, + settings.getAccessApprovalServiceAccountSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listApprovalRequestsMethodDescriptor); + methodDescriptors.add(getApprovalRequestMethodDescriptor); + methodDescriptors.add(approveApprovalRequestMethodDescriptor); + methodDescriptors.add(dismissApprovalRequestMethodDescriptor); + methodDescriptors.add(invalidateApprovalRequestMethodDescriptor); + methodDescriptors.add(getAccessApprovalSettingsMethodDescriptor); + methodDescriptors.add(updateAccessApprovalSettingsMethodDescriptor); + methodDescriptors.add(deleteAccessApprovalSettingsMethodDescriptor); + methodDescriptors.add(getAccessApprovalServiceAccountMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + listApprovalRequestsCallable() { + return listApprovalRequestsCallable; + } + + @Override + public UnaryCallable + listApprovalRequestsPagedCallable() { + return listApprovalRequestsPagedCallable; + } + + @Override + public UnaryCallable getApprovalRequestCallable() { + return getApprovalRequestCallable; + } + + @Override + public UnaryCallable + approveApprovalRequestCallable() { + return approveApprovalRequestCallable; + } + + @Override + public UnaryCallable + dismissApprovalRequestCallable() { + return dismissApprovalRequestCallable; + } + + @Override + public UnaryCallable + invalidateApprovalRequestCallable() { + return invalidateApprovalRequestCallable; + } + + @Override + public UnaryCallable + getAccessApprovalSettingsCallable() { + return getAccessApprovalSettingsCallable; + } + + @Override + public UnaryCallable + updateAccessApprovalSettingsCallable() { + return updateAccessApprovalSettingsCallable; + } + + @Override + public UnaryCallable + deleteAccessApprovalSettingsCallable() { + return deleteAccessApprovalSettingsCallable; + } + + @Override + public UnaryCallable + getAccessApprovalServiceAccountCallable() { + return getAccessApprovalServiceAccountCallable; + } + + @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/java-accessapproval/google-cloud-accessapproval/src/test/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClientHttpJsonTest.java b/java-accessapproval/google-cloud-accessapproval/src/test/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClientHttpJsonTest.java new file mode 100644 index 000000000000..7ffe1d3652cc --- /dev/null +++ b/java-accessapproval/google-cloud-accessapproval/src/test/java/com/google/cloud/accessapproval/v1/AccessApprovalAdminClientHttpJsonTest.java @@ -0,0 +1,874 @@ +/* + * 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.cloud.accessapproval.v1; + +import static com.google.cloud.accessapproval.v1.AccessApprovalAdminClient.ListApprovalRequestsPagedResponse; + +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.cloud.accessapproval.v1.stub.HttpJsonAccessApprovalStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +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 AccessApprovalAdminClientHttpJsonTest { + private static MockHttpService mockService; + private static AccessApprovalAdminClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAccessApprovalStub.getMethodDescriptors(), + AccessApprovalAdminSettings.getDefaultEndpoint()); + AccessApprovalAdminSettings settings = + AccessApprovalAdminSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AccessApprovalAdminSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AccessApprovalAdminClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listApprovalRequestsTest() throws Exception { + ApprovalRequest responsesElement = ApprovalRequest.newBuilder().build(); + ListApprovalRequestsResponse expectedResponse = + ListApprovalRequestsResponse.newBuilder() + .setNextPageToken("") + .addAllApprovalRequests(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListApprovalRequestsPagedResponse pagedListResponse = client.listApprovalRequests(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getApprovalRequestsList().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 listApprovalRequestsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + client.listApprovalRequests(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listApprovalRequestsTest2() throws Exception { + ApprovalRequest responsesElement = ApprovalRequest.newBuilder().build(); + ListApprovalRequestsResponse expectedResponse = + ListApprovalRequestsResponse.newBuilder() + .setNextPageToken("") + .addAllApprovalRequests(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListApprovalRequestsPagedResponse pagedListResponse = client.listApprovalRequests(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getApprovalRequestsList().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 listApprovalRequestsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + client.listApprovalRequests(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listApprovalRequestsTest3() throws Exception { + ApprovalRequest responsesElement = ApprovalRequest.newBuilder().build(); + ListApprovalRequestsResponse expectedResponse = + ListApprovalRequestsResponse.newBuilder() + .setNextPageToken("") + .addAllApprovalRequests(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListApprovalRequestsPagedResponse pagedListResponse = client.listApprovalRequests(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getApprovalRequestsList().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 listApprovalRequestsExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listApprovalRequests(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listApprovalRequestsTest4() throws Exception { + ApprovalRequest responsesElement = ApprovalRequest.newBuilder().build(); + ListApprovalRequestsResponse expectedResponse = + ListApprovalRequestsResponse.newBuilder() + .setNextPageToken("") + .addAllApprovalRequests(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-2353"; + + ListApprovalRequestsPagedResponse pagedListResponse = client.listApprovalRequests(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getApprovalRequestsList().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 listApprovalRequestsExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-2353"; + client.listApprovalRequests(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getApprovalRequestTest() throws Exception { + ApprovalRequest expectedResponse = + ApprovalRequest.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setRequestedResourceName("requestedResourceName-1218563513") + .setRequestedResourceProperties(ResourceProperties.newBuilder().build()) + .setRequestedReason(AccessReason.newBuilder().build()) + .setRequestedLocations(AccessLocations.newBuilder().build()) + .setRequestTime(Timestamp.newBuilder().build()) + .setRequestedExpiration(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ApprovalRequestName name = + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]"); + + ApprovalRequest actualResponse = client.getApprovalRequest(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 getApprovalRequestExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ApprovalRequestName name = + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]"); + client.getApprovalRequest(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getApprovalRequestTest2() throws Exception { + ApprovalRequest expectedResponse = + ApprovalRequest.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setRequestedResourceName("requestedResourceName-1218563513") + .setRequestedResourceProperties(ResourceProperties.newBuilder().build()) + .setRequestedReason(AccessReason.newBuilder().build()) + .setRequestedLocations(AccessLocations.newBuilder().build()) + .setRequestTime(Timestamp.newBuilder().build()) + .setRequestedExpiration(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-6513/approvalRequests/approvalRequest-6513"; + + ApprovalRequest actualResponse = client.getApprovalRequest(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 getApprovalRequestExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-6513/approvalRequests/approvalRequest-6513"; + client.getApprovalRequest(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void approveApprovalRequestTest() throws Exception { + ApprovalRequest expectedResponse = + ApprovalRequest.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setRequestedResourceName("requestedResourceName-1218563513") + .setRequestedResourceProperties(ResourceProperties.newBuilder().build()) + .setRequestedReason(AccessReason.newBuilder().build()) + .setRequestedLocations(AccessLocations.newBuilder().build()) + .setRequestTime(Timestamp.newBuilder().build()) + .setRequestedExpiration(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ApproveApprovalRequestMessage request = + ApproveApprovalRequestMessage.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setExpireTime(Timestamp.newBuilder().build()) + .build(); + + ApprovalRequest actualResponse = client.approveApprovalRequest(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 approveApprovalRequestExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ApproveApprovalRequestMessage request = + ApproveApprovalRequestMessage.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName( + "[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setExpireTime(Timestamp.newBuilder().build()) + .build(); + client.approveApprovalRequest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void dismissApprovalRequestTest() throws Exception { + ApprovalRequest expectedResponse = + ApprovalRequest.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setRequestedResourceName("requestedResourceName-1218563513") + .setRequestedResourceProperties(ResourceProperties.newBuilder().build()) + .setRequestedReason(AccessReason.newBuilder().build()) + .setRequestedLocations(AccessLocations.newBuilder().build()) + .setRequestTime(Timestamp.newBuilder().build()) + .setRequestedExpiration(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + DismissApprovalRequestMessage request = + DismissApprovalRequestMessage.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .build(); + + ApprovalRequest actualResponse = client.dismissApprovalRequest(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 dismissApprovalRequestExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DismissApprovalRequestMessage request = + DismissApprovalRequestMessage.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName( + "[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .build(); + client.dismissApprovalRequest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void invalidateApprovalRequestTest() throws Exception { + ApprovalRequest expectedResponse = + ApprovalRequest.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .setRequestedResourceName("requestedResourceName-1218563513") + .setRequestedResourceProperties(ResourceProperties.newBuilder().build()) + .setRequestedReason(AccessReason.newBuilder().build()) + .setRequestedLocations(AccessLocations.newBuilder().build()) + .setRequestTime(Timestamp.newBuilder().build()) + .setRequestedExpiration(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + InvalidateApprovalRequestMessage request = + InvalidateApprovalRequestMessage.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName("[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .build(); + + ApprovalRequest actualResponse = client.invalidateApprovalRequest(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 invalidateApprovalRequestExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + InvalidateApprovalRequestMessage request = + InvalidateApprovalRequestMessage.newBuilder() + .setName( + ApprovalRequestName.ofProjectApprovalRequestName( + "[PROJECT]", "[APPROVAL_REQUEST]") + .toString()) + .build(); + client.invalidateApprovalRequest(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getAccessApprovalSettingsTest() throws Exception { + AccessApprovalSettings expectedResponse = + AccessApprovalSettings.newBuilder() + .setName(AccessApprovalSettingsName.ofProjectName("[PROJECT]").toString()) + .addAllNotificationEmails(new ArrayList()) + .addAllEnrolledServices(new ArrayList()) + .setEnrolledAncestor(true) + .setActiveKeyVersion("activeKeyVersion1352190239") + .setAncestorHasActiveKeyVersion(true) + .setInvalidKeyVersion(true) + .build(); + mockService.addResponse(expectedResponse); + + AccessApprovalSettingsName name = AccessApprovalSettingsName.ofProjectName("[PROJECT]"); + + AccessApprovalSettings actualResponse = client.getAccessApprovalSettings(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 getAccessApprovalSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AccessApprovalSettingsName name = AccessApprovalSettingsName.ofProjectName("[PROJECT]"); + client.getAccessApprovalSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getAccessApprovalSettingsTest2() throws Exception { + AccessApprovalSettings expectedResponse = + AccessApprovalSettings.newBuilder() + .setName(AccessApprovalSettingsName.ofProjectName("[PROJECT]").toString()) + .addAllNotificationEmails(new ArrayList()) + .addAllEnrolledServices(new ArrayList()) + .setEnrolledAncestor(true) + .setActiveKeyVersion("activeKeyVersion1352190239") + .setAncestorHasActiveKeyVersion(true) + .setInvalidKeyVersion(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9033/accessApprovalSettings"; + + AccessApprovalSettings actualResponse = client.getAccessApprovalSettings(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 getAccessApprovalSettingsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9033/accessApprovalSettings"; + client.getAccessApprovalSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateAccessApprovalSettingsTest() throws Exception { + AccessApprovalSettings expectedResponse = + AccessApprovalSettings.newBuilder() + .setName(AccessApprovalSettingsName.ofProjectName("[PROJECT]").toString()) + .addAllNotificationEmails(new ArrayList()) + .addAllEnrolledServices(new ArrayList()) + .setEnrolledAncestor(true) + .setActiveKeyVersion("activeKeyVersion1352190239") + .setAncestorHasActiveKeyVersion(true) + .setInvalidKeyVersion(true) + .build(); + mockService.addResponse(expectedResponse); + + AccessApprovalSettings settings = + AccessApprovalSettings.newBuilder() + .setName(AccessApprovalSettingsName.ofProjectName("[PROJECT]").toString()) + .addAllNotificationEmails(new ArrayList()) + .addAllEnrolledServices(new ArrayList()) + .setEnrolledAncestor(true) + .setActiveKeyVersion("activeKeyVersion1352190239") + .setAncestorHasActiveKeyVersion(true) + .setInvalidKeyVersion(true) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + AccessApprovalSettings actualResponse = + client.updateAccessApprovalSettings(settings, 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 updateAccessApprovalSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AccessApprovalSettings settings = + AccessApprovalSettings.newBuilder() + .setName(AccessApprovalSettingsName.ofProjectName("[PROJECT]").toString()) + .addAllNotificationEmails(new ArrayList()) + .addAllEnrolledServices(new ArrayList()) + .setEnrolledAncestor(true) + .setActiveKeyVersion("activeKeyVersion1352190239") + .setAncestorHasActiveKeyVersion(true) + .setInvalidKeyVersion(true) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateAccessApprovalSettings(settings, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteAccessApprovalSettingsTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + AccessApprovalSettingsName name = AccessApprovalSettingsName.ofProjectName("[PROJECT]"); + + client.deleteAccessApprovalSettings(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 deleteAccessApprovalSettingsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AccessApprovalSettingsName name = AccessApprovalSettingsName.ofProjectName("[PROJECT]"); + client.deleteAccessApprovalSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteAccessApprovalSettingsTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9033/accessApprovalSettings"; + + client.deleteAccessApprovalSettings(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 deleteAccessApprovalSettingsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9033/accessApprovalSettings"; + client.deleteAccessApprovalSettings(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getAccessApprovalServiceAccountTest() throws Exception { + AccessApprovalServiceAccount expectedResponse = + AccessApprovalServiceAccount.newBuilder() + .setName("name3373707") + .setAccountEmail("accountEmail1067197807") + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9017/serviceAccount"; + + AccessApprovalServiceAccount actualResponse = client.getAccessApprovalServiceAccount(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 getAccessApprovalServiceAccountExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9017/serviceAccount"; + client.getAccessApprovalServiceAccount(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-accessapproval/samples/snippets/generated/com/google/cloud/accessapproval/v1/accessapprovaladminclient/create/SyncCreateSetCredentialsProvider1.java b/java-accessapproval/samples/snippets/generated/com/google/cloud/accessapproval/v1/accessapprovaladminclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..2d37e0f6512c --- /dev/null +++ b/java-accessapproval/samples/snippets/generated/com/google/cloud/accessapproval/v1/accessapprovaladminclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,41 @@ +/* + * 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.cloud.accessapproval.v1.samples; + +// [START accessapproval_v1_generated_accessapprovaladminclient_create_setcredentialsprovider1_sync] +import com.google.cloud.accessapproval.v1.AccessApprovalAdminClient; +import com.google.cloud.accessapproval.v1.AccessApprovalAdminSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AccessApprovalAdminSettings accessApprovalAdminSettings = + AccessApprovalAdminSettings.newBuilder() + .setTransportChannelProvider( + AccessApprovalAdminSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AccessApprovalAdminClient accessApprovalAdminClient = + AccessApprovalAdminClient.create(accessApprovalAdminSettings); + } +} +// [END accessapproval_v1_generated_accessapprovaladminclient_create_setcredentialsprovider1_sync]