From 7e231d1abd48beb94031a176eae7420331f90e4d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 16 Jun 2022 10:28:02 -0400 Subject: [PATCH] chore: update gapic-generator-java (#239) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: Integrate new gapic-generator-java and rules_gapic PiperOrigin-RevId: 454027580 Source-Link: https://github.com/googleapis/googleapis/commit/1b222777baa702e7135610355706570ed2b56318 Source-Link: https://github.com/googleapis/googleapis-gen/commit/e04cea20d0d12eb5c3bdb360a9e72b654edcb638 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTA0Y2VhMjBkMGQxMmViNWMzYmRiMzYwYTllNzJiNjU0ZWRjYjYzOCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Add Java REST transport to analytics, servicecontrol, servicemanagement, serviceusage and langauge APIs PiperOrigin-RevId: 454254635 Source-Link: https://github.com/googleapis/googleapis/commit/84fb82208e15c45d1732b5eeba7f70828935b97b Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ffb61264d6fb634c430829dd2da75c5bed08304 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGZmYjYxMjY0ZDZmYjYzNGM0MzA4MjlkZDJkYTc1YzViZWQwODMwNCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: update gapic-generator-java PiperOrigin-RevId: 454939894 Source-Link: https://github.com/googleapis/googleapis/commit/519ca445965b3f94f9e32ae511c154488d2054e9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/fc639d21a7cbc30aa0a9b862586942a0fb46c5c8 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZmM2MzlkMjFhN2NiYzMwYWEwYTliODYyNTg2OTQyYTBmYjQ2YzVjOCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update pom.xml * Update pom.xml * Update pom.xml Co-authored-by: Owl Bot Co-authored-by: Neenu Shaji --- .../google-cloud-service-usage/pom.xml | 16 + .../serviceusage/v1/ServiceUsageClient.java | 39 +- .../serviceusage/v1/ServiceUsageSettings.java | 23 +- .../HttpJsonServiceUsageCallableFactory.java | 105 ++ .../v1/stub/HttpJsonServiceUsageStub.java | 542 ++++++ .../v1/stub/ServiceUsageStub.java | 6 +- .../v1/stub/ServiceUsageStubSettings.java | 53 +- .../v1beta1/ServiceUsageClient.java | 45 +- .../v1beta1/ServiceUsageSettings.java | 23 +- .../HttpJsonServiceUsageCallableFactory.java | 105 ++ .../stub/HttpJsonServiceUsageStub.java | 1511 +++++++++++++++++ .../v1beta1/stub/ServiceUsageStub.java | 6 +- .../stub/ServiceUsageStubSettings.java | 53 +- .../v1/ServiceUsageClientHttpJsonTest.java | 410 +++++ .../ServiceUsageClientHttpJsonTest.java | 1225 +++++++++++++ 15 files changed, 4135 insertions(+), 27 deletions(-) create mode 100644 java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageCallableFactory.java create mode 100644 java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageStub.java create mode 100644 java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageCallableFactory.java create mode 100644 java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageStub.java create mode 100644 java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1/ServiceUsageClientHttpJsonTest.java create mode 100644 java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1beta1/ServiceUsageClientHttpJsonTest.java diff --git a/java-service-usage/google-cloud-service-usage/pom.xml b/java-service-usage/google-cloud-service-usage/pom.xml index 06dd6da6676a..5d8896e24f5d 100644 --- a/java-service-usage/google-cloud-service-usage/pom.xml +++ b/java-service-usage/google-cloud-service-usage/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -86,12 +90,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-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageClient.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageClient.java index 68753dd66b97..2233fe05cfb7 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageClient.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; 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; @@ -30,7 +31,6 @@ import com.google.api.serviceusage.v1.stub.ServiceUsageStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -104,13 +104,28 @@ * ServiceUsageClient serviceUsageClient = ServiceUsageClient.create(serviceUsageSettings); * } * + *

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.
+ * ServiceUsageSettings serviceUsageSettings =
+ *     ServiceUsageSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             ServiceUsageSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * ServiceUsageClient serviceUsageClient = ServiceUsageClient.create(serviceUsageSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class ServiceUsageClient implements BackgroundResource { private final ServiceUsageSettings settings; private final ServiceUsageStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of ServiceUsageClient with default settings. */ public static final ServiceUsageClient create() throws IOException { @@ -141,13 +156,17 @@ public static final ServiceUsageClient create(ServiceUsageStub stub) { protected ServiceUsageClient(ServiceUsageSettings settings) throws IOException { this.settings = settings; this.stub = ((ServiceUsageStubSettings) 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()); } protected ServiceUsageClient(ServiceUsageStub 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 ServiceUsageSettings getSettings() { @@ -162,10 +181,18 @@ public ServiceUsageStub 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Enable a service so that it can be used with a project. @@ -477,7 +504,7 @@ public final ListServicesPagedResponse listServices(ListServicesRequest request) * .build(); * while (true) { * ListServicesResponse response = serviceUsageClient.listServicesCallable().call(request); - * for (Service element : response.getResponsesList()) { + * for (Service element : response.getServicesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageSettings.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageSettings.java index 882ff5b4b763..d64549af1666 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageSettings.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/ServiceUsageSettings.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; @@ -148,11 +149,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return ServiceUsageStubSettings.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 ServiceUsageStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return ServiceUsageStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return ServiceUsageStubSettings.defaultTransportChannelProvider(); } @@ -162,11 +170,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return ServiceUsageStubSettings.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); @@ -204,6 +218,11 @@ private static Builder createDefault() { return new Builder(ServiceUsageStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(ServiceUsageStubSettings.newHttpJsonBuilder()); + } + public ServiceUsageStubSettings.Builder getStubSettingsBuilder() { return ((ServiceUsageStubSettings.Builder) getStubSettings()); } diff --git a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageCallableFactory.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageCallableFactory.java new file mode 100644 index 000000000000..8b02926acc64 --- /dev/null +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageCallableFactory.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.api.serviceusage.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 ServiceUsage service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonServiceUsageCallableFactory + 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-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageStub.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageStub.java new file mode 100644 index 000000000000..52725089a81b --- /dev/null +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/HttpJsonServiceUsageStub.java @@ -0,0 +1,542 @@ +/* + * 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.api.serviceusage.v1.stub; + +import static com.google.api.serviceusage.v1.ServiceUsageClient.ListServicesPagedResponse; + +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.api.serviceusage.v1.BatchEnableServicesRequest; +import com.google.api.serviceusage.v1.BatchEnableServicesResponse; +import com.google.api.serviceusage.v1.BatchGetServicesRequest; +import com.google.api.serviceusage.v1.BatchGetServicesResponse; +import com.google.api.serviceusage.v1.DisableServiceRequest; +import com.google.api.serviceusage.v1.DisableServiceResponse; +import com.google.api.serviceusage.v1.EnableServiceRequest; +import com.google.api.serviceusage.v1.EnableServiceResponse; +import com.google.api.serviceusage.v1.GetServiceRequest; +import com.google.api.serviceusage.v1.ListServicesRequest; +import com.google.api.serviceusage.v1.ListServicesResponse; +import com.google.api.serviceusage.v1.OperationMetadata; +import com.google.api.serviceusage.v1.Service; +import com.google.longrunning.Operation; +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 ServiceUsage service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonServiceUsageStub extends ServiceUsageStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(BatchEnableServicesResponse.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(DisableServiceResponse.getDescriptor()) + .add(EnableServiceResponse.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + enableServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1.ServiceUsage/EnableService") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/services/*}:enable", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (EnableServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + disableServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1.ServiceUsage/DisableService") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/services/*}:disable", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DisableServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor getServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1.ServiceUsage/GetService") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/services/*}", + 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(Service.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1.ServiceUsage/ListServices") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/services", + 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(ListServicesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + batchEnableServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1.ServiceUsage/BatchEnableServices") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/services:batchEnable", + 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( + (BatchEnableServicesRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + batchGetServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1.ServiceUsage/BatchGetServices") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/services:batchGet", + 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, "names", request.getNamesList()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BatchGetServicesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable enableServiceCallable; + private final OperationCallable + enableServiceOperationCallable; + private final UnaryCallable disableServiceCallable; + private final OperationCallable + disableServiceOperationCallable; + private final UnaryCallable getServiceCallable; + private final UnaryCallable listServicesCallable; + private final UnaryCallable + listServicesPagedCallable; + private final UnaryCallable batchEnableServicesCallable; + private final OperationCallable< + BatchEnableServicesRequest, BatchEnableServicesResponse, OperationMetadata> + batchEnableServicesOperationCallable; + private final UnaryCallable + batchGetServicesCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonServiceUsageStub create(ServiceUsageStubSettings settings) + throws IOException { + return new HttpJsonServiceUsageStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonServiceUsageStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonServiceUsageStub( + ServiceUsageStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonServiceUsageStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonServiceUsageStub( + ServiceUsageStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonServiceUsageStub, 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 HttpJsonServiceUsageStub(ServiceUsageStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonServiceUsageCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonServiceUsageStub, 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 HttpJsonServiceUsageStub( + ServiceUsageStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings enableServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(enableServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings disableServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(disableServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchEnableServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchEnableServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchGetServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchGetServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.enableServiceCallable = + callableFactory.createUnaryCallable( + enableServiceTransportSettings, settings.enableServiceSettings(), clientContext); + this.enableServiceOperationCallable = + callableFactory.createOperationCallable( + enableServiceTransportSettings, + settings.enableServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.disableServiceCallable = + callableFactory.createUnaryCallable( + disableServiceTransportSettings, settings.disableServiceSettings(), clientContext); + this.disableServiceOperationCallable = + callableFactory.createOperationCallable( + disableServiceTransportSettings, + settings.disableServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getServiceCallable = + callableFactory.createUnaryCallable( + getServiceTransportSettings, settings.getServiceSettings(), clientContext); + this.listServicesCallable = + callableFactory.createUnaryCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.listServicesPagedCallable = + callableFactory.createPagedCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.batchEnableServicesCallable = + callableFactory.createUnaryCallable( + batchEnableServicesTransportSettings, + settings.batchEnableServicesSettings(), + clientContext); + this.batchEnableServicesOperationCallable = + callableFactory.createOperationCallable( + batchEnableServicesTransportSettings, + settings.batchEnableServicesOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.batchGetServicesCallable = + callableFactory.createUnaryCallable( + batchGetServicesTransportSettings, settings.batchGetServicesSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(enableServiceMethodDescriptor); + methodDescriptors.add(disableServiceMethodDescriptor); + methodDescriptors.add(getServiceMethodDescriptor); + methodDescriptors.add(listServicesMethodDescriptor); + methodDescriptors.add(batchEnableServicesMethodDescriptor); + methodDescriptors.add(batchGetServicesMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable enableServiceCallable() { + return enableServiceCallable; + } + + @Override + public OperationCallable + enableServiceOperationCallable() { + return enableServiceOperationCallable; + } + + @Override + public UnaryCallable disableServiceCallable() { + return disableServiceCallable; + } + + @Override + public OperationCallable + disableServiceOperationCallable() { + return disableServiceOperationCallable; + } + + @Override + public UnaryCallable getServiceCallable() { + return getServiceCallable; + } + + @Override + public UnaryCallable listServicesCallable() { + return listServicesCallable; + } + + @Override + public UnaryCallable listServicesPagedCallable() { + return listServicesPagedCallable; + } + + @Override + public UnaryCallable batchEnableServicesCallable() { + return batchEnableServicesCallable; + } + + @Override + public OperationCallable< + BatchEnableServicesRequest, BatchEnableServicesResponse, OperationMetadata> + batchEnableServicesOperationCallable() { + return batchEnableServicesOperationCallable; + } + + @Override + public UnaryCallable + batchGetServicesCallable() { + return batchGetServicesCallable; + } + + @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-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStub.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStub.java index 68fc209ffee9..1a4ca8dd169d 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStub.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStub.java @@ -48,7 +48,11 @@ public abstract class ServiceUsageStub 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/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStubSettings.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStubSettings.java index 1892ccd69393..4663174feefd 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStubSettings.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1/stub/ServiceUsageStubSettings.java @@ -28,6 +28,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; @@ -241,6 +244,11 @@ public ServiceUsageStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcServiceUsageStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonServiceUsageStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -273,18 +281,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(ServiceUsageStubSettings.class)) @@ -292,11 +307,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(ServiceUsageStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ServiceUsageStubSettings.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); @@ -437,6 +471,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 .enableServiceSettings() diff --git a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageClient.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageClient.java index 28408ca0edec..f2a1b360e2d9 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageClient.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageClient.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; @@ -31,7 +32,6 @@ import com.google.api.serviceusage.v1beta1.stub.ServiceUsageStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; @@ -102,6 +102,20 @@ * ServiceUsageClient serviceUsageClient = ServiceUsageClient.create(serviceUsageSettings); * } * + *

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.
+ * ServiceUsageSettings serviceUsageSettings =
+ *     ServiceUsageSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             ServiceUsageSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * ServiceUsageClient serviceUsageClient = ServiceUsageClient.create(serviceUsageSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -109,7 +123,8 @@ public class ServiceUsageClient implements BackgroundResource { private final ServiceUsageSettings settings; private final ServiceUsageStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of ServiceUsageClient with default settings. */ public static final ServiceUsageClient create() throws IOException { @@ -140,13 +155,17 @@ public static final ServiceUsageClient create(ServiceUsageStub stub) { protected ServiceUsageClient(ServiceUsageSettings settings) throws IOException { this.settings = settings; this.stub = ((ServiceUsageStubSettings) 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()); } protected ServiceUsageClient(ServiceUsageStub 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 ServiceUsageSettings getSettings() { @@ -161,10 +180,18 @@ public ServiceUsageStub 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Enables a service so that it can be used with a project. @@ -493,7 +520,7 @@ public final ListServicesPagedResponse listServices(ListServicesRequest request) * .build(); * while (true) { * ListServicesResponse response = serviceUsageClient.listServicesCallable().call(request); - * for (Service element : response.getResponsesList()) { + * for (Service element : response.getServicesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -702,7 +729,7 @@ public final ListConsumerQuotaMetricsPagedResponse listConsumerQuotaMetrics( * while (true) { * ListConsumerQuotaMetricsResponse response = * serviceUsageClient.listConsumerQuotaMetricsCallable().call(request); - * for (ConsumerQuotaMetric element : response.getResponsesList()) { + * for (ConsumerQuotaMetric element : response.getMetricsList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1172,7 +1199,7 @@ public final ListAdminOverridesPagedResponse listAdminOverrides( * while (true) { * ListAdminOverridesResponse response = * serviceUsageClient.listAdminOverridesCallable().call(request); - * for (QuotaOverride element : response.getResponsesList()) { + * for (QuotaOverride element : response.getOverridesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1628,7 +1655,7 @@ public final ListConsumerOverridesPagedResponse listConsumerOverrides( * while (true) { * ListConsumerOverridesResponse response = * serviceUsageClient.listConsumerOverridesCallable().call(request); - * for (QuotaOverride element : response.getResponsesList()) { + * for (QuotaOverride element : response.getOverridesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageSettings.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageSettings.java index 092c145bebdd..cdb4d47e5d75 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageSettings.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/ServiceUsageSettings.java @@ -26,6 +26,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; @@ -333,11 +334,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return ServiceUsageStubSettings.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 ServiceUsageStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return ServiceUsageStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return ServiceUsageStubSettings.defaultTransportChannelProvider(); } @@ -347,11 +355,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return ServiceUsageStubSettings.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); @@ -389,6 +403,11 @@ private static Builder createDefault() { return new Builder(ServiceUsageStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(ServiceUsageStubSettings.newHttpJsonBuilder()); + } + public ServiceUsageStubSettings.Builder getStubSettingsBuilder() { return ((ServiceUsageStubSettings.Builder) getStubSettings()); } diff --git a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageCallableFactory.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageCallableFactory.java new file mode 100644 index 000000000000..8988fc821944 --- /dev/null +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageCallableFactory.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.api.serviceusage.v1beta1.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 ServiceUsage service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonServiceUsageCallableFactory + 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-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageStub.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageStub.java new file mode 100644 index 000000000000..5e7aa4314955 --- /dev/null +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/HttpJsonServiceUsageStub.java @@ -0,0 +1,1511 @@ +/* + * 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.api.serviceusage.v1beta1.stub; + +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListAdminOverridesPagedResponse; +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListConsumerOverridesPagedResponse; +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListConsumerQuotaMetricsPagedResponse; +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListServicesPagedResponse; + +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.api.serviceusage.v1beta1.BatchEnableServicesRequest; +import com.google.api.serviceusage.v1beta1.ConsumerQuotaLimit; +import com.google.api.serviceusage.v1beta1.ConsumerQuotaMetric; +import com.google.api.serviceusage.v1beta1.CreateAdminOverrideRequest; +import com.google.api.serviceusage.v1beta1.CreateConsumerOverrideRequest; +import com.google.api.serviceusage.v1beta1.DeleteAdminOverrideRequest; +import com.google.api.serviceusage.v1beta1.DeleteConsumerOverrideRequest; +import com.google.api.serviceusage.v1beta1.DisableServiceRequest; +import com.google.api.serviceusage.v1beta1.EnableServiceRequest; +import com.google.api.serviceusage.v1beta1.GenerateServiceIdentityRequest; +import com.google.api.serviceusage.v1beta1.GetConsumerQuotaLimitRequest; +import com.google.api.serviceusage.v1beta1.GetConsumerQuotaMetricRequest; +import com.google.api.serviceusage.v1beta1.GetServiceRequest; +import com.google.api.serviceusage.v1beta1.ImportAdminOverridesMetadata; +import com.google.api.serviceusage.v1beta1.ImportAdminOverridesRequest; +import com.google.api.serviceusage.v1beta1.ImportAdminOverridesResponse; +import com.google.api.serviceusage.v1beta1.ImportConsumerOverridesMetadata; +import com.google.api.serviceusage.v1beta1.ImportConsumerOverridesRequest; +import com.google.api.serviceusage.v1beta1.ImportConsumerOverridesResponse; +import com.google.api.serviceusage.v1beta1.ListAdminOverridesRequest; +import com.google.api.serviceusage.v1beta1.ListAdminOverridesResponse; +import com.google.api.serviceusage.v1beta1.ListConsumerOverridesRequest; +import com.google.api.serviceusage.v1beta1.ListConsumerOverridesResponse; +import com.google.api.serviceusage.v1beta1.ListConsumerQuotaMetricsRequest; +import com.google.api.serviceusage.v1beta1.ListConsumerQuotaMetricsResponse; +import com.google.api.serviceusage.v1beta1.ListServicesRequest; +import com.google.api.serviceusage.v1beta1.ListServicesResponse; +import com.google.api.serviceusage.v1beta1.OperationMetadata; +import com.google.api.serviceusage.v1beta1.QuotaOverride; +import com.google.api.serviceusage.v1beta1.Service; +import com.google.api.serviceusage.v1beta1.ServiceIdentity; +import com.google.api.serviceusage.v1beta1.UpdateAdminOverrideRequest; +import com.google.api.serviceusage.v1beta1.UpdateConsumerOverrideRequest; +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 ServiceUsage service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonServiceUsageStub extends ServiceUsageStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(Empty.getDescriptor()) + .add(ServiceIdentity.getDescriptor()) + .add(ImportConsumerOverridesResponse.getDescriptor()) + .add(ImportAdminOverridesResponse.getDescriptor()) + .add(QuotaOverride.getDescriptor()) + .add(ImportAdminOverridesMetadata.getDescriptor()) + .add(OperationMetadata.getDescriptor()) + .add(ImportConsumerOverridesMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + enableServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/EnableService") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*}:enable", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (EnableServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + disableServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/DisableService") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*}:disable", + 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 -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DisableServiceRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor getServiceMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/GetService") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*}", + 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(Service.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/ListServices") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*}/services", + 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(ListServicesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + batchEnableServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/BatchEnableServices") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*}/services:batchEnable", + 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( + (BatchEnableServicesRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + ListConsumerQuotaMetricsRequest, ListConsumerQuotaMetricsResponse> + listConsumerQuotaMetricsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/ListConsumerQuotaMetrics") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*}/consumerQuotaMetrics", + 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()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListConsumerQuotaMetricsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getConsumerQuotaMetricMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/GetConsumerQuotaMetric") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*/consumerQuotaMetrics/*}", + 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(ConsumerQuotaMetric.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getConsumerQuotaLimitMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/GetConsumerQuotaLimit") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*/consumerQuotaMetrics/*/limits/*}", + 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(ConsumerQuotaLimit.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createAdminOverrideMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/CreateAdminOverride") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*/consumerQuotaMetrics/*/limits/*}/adminOverrides", + 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, "force", request.getForce()); + serializer.putQueryParam( + fields, "forceOnly", request.getForceOnlyList()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("override", request.getOverride())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateAdminOverrideRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateAdminOverrideMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/UpdateAdminOverride") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*/consumerQuotaMetrics/*/limits/*/adminOverrides/*}", + 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()); + serializer.putQueryParam( + fields, "forceOnly", request.getForceOnlyList()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("override", request.getOverride())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateAdminOverrideRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteAdminOverrideMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/DeleteAdminOverride") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*/consumerQuotaMetrics/*/limits/*/adminOverrides/*}", + 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()); + serializer.putQueryParam( + fields, "forceOnly", request.getForceOnlyList()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteAdminOverrideRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listAdminOverridesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.api.serviceusage.v1beta1.ServiceUsage/ListAdminOverrides") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*/consumerQuotaMetrics/*/limits/*}/adminOverrides", + 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(ListAdminOverridesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + importAdminOverridesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/ImportAdminOverrides") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*}/consumerQuotaMetrics:importAdminOverrides", + 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( + (ImportAdminOverridesRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + createConsumerOverrideMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/CreateConsumerOverride") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*/consumerQuotaMetrics/*/limits/*}/consumerOverrides", + 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, "force", request.getForce()); + serializer.putQueryParam( + fields, "forceOnly", request.getForceOnlyList()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("override", request.getOverride())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateConsumerOverrideRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + updateConsumerOverrideMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/UpdateConsumerOverride") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*/consumerQuotaMetrics/*/limits/*/consumerOverrides/*}", + 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()); + serializer.putQueryParam( + fields, "forceOnly", request.getForceOnlyList()); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("override", request.getOverride())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (UpdateConsumerOverrideRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + deleteConsumerOverrideMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/DeleteConsumerOverride") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=*/*/services/*/consumerQuotaMetrics/*/limits/*/consumerOverrides/*}", + 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()); + serializer.putQueryParam( + fields, "forceOnly", request.getForceOnlyList()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteConsumerOverrideRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor< + ListConsumerOverridesRequest, ListConsumerOverridesResponse> + listConsumerOverridesMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/ListConsumerOverrides") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*/consumerQuotaMetrics/*/limits/*}/consumerOverrides", + 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(ListConsumerOverridesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + importConsumerOverridesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/ImportConsumerOverrides") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*}/consumerQuotaMetrics:importConsumerOverrides", + 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( + (ImportConsumerOverridesRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + generateServiceIdentityMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.api.serviceusage.v1beta1.ServiceUsage/GenerateServiceIdentity") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=*/*/services/*}:generateServiceIdentity", + 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 -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (GenerateServiceIdentityRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable enableServiceCallable; + private final OperationCallable + enableServiceOperationCallable; + private final UnaryCallable disableServiceCallable; + private final OperationCallable + disableServiceOperationCallable; + private final UnaryCallable getServiceCallable; + private final UnaryCallable listServicesCallable; + private final UnaryCallable + listServicesPagedCallable; + private final UnaryCallable batchEnableServicesCallable; + private final OperationCallable + batchEnableServicesOperationCallable; + private final UnaryCallable + listConsumerQuotaMetricsCallable; + private final UnaryCallable< + ListConsumerQuotaMetricsRequest, ListConsumerQuotaMetricsPagedResponse> + listConsumerQuotaMetricsPagedCallable; + private final UnaryCallable + getConsumerQuotaMetricCallable; + private final UnaryCallable + getConsumerQuotaLimitCallable; + private final UnaryCallable createAdminOverrideCallable; + private final OperationCallable + createAdminOverrideOperationCallable; + private final UnaryCallable updateAdminOverrideCallable; + private final OperationCallable + updateAdminOverrideOperationCallable; + private final UnaryCallable deleteAdminOverrideCallable; + private final OperationCallable + deleteAdminOverrideOperationCallable; + private final UnaryCallable + listAdminOverridesCallable; + private final UnaryCallable + listAdminOverridesPagedCallable; + private final UnaryCallable importAdminOverridesCallable; + private final OperationCallable< + ImportAdminOverridesRequest, ImportAdminOverridesResponse, ImportAdminOverridesMetadata> + importAdminOverridesOperationCallable; + private final UnaryCallable + createConsumerOverrideCallable; + private final OperationCallable + createConsumerOverrideOperationCallable; + private final UnaryCallable + updateConsumerOverrideCallable; + private final OperationCallable + updateConsumerOverrideOperationCallable; + private final UnaryCallable + deleteConsumerOverrideCallable; + private final OperationCallable + deleteConsumerOverrideOperationCallable; + private final UnaryCallable + listConsumerOverridesCallable; + private final UnaryCallable + listConsumerOverridesPagedCallable; + private final UnaryCallable + importConsumerOverridesCallable; + private final OperationCallable< + ImportConsumerOverridesRequest, + ImportConsumerOverridesResponse, + ImportConsumerOverridesMetadata> + importConsumerOverridesOperationCallable; + private final UnaryCallable + generateServiceIdentityCallable; + private final OperationCallable + generateServiceIdentityOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonServiceUsageStub create(ServiceUsageStubSettings settings) + throws IOException { + return new HttpJsonServiceUsageStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonServiceUsageStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonServiceUsageStub( + ServiceUsageStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonServiceUsageStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonServiceUsageStub( + ServiceUsageStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonServiceUsageStub, 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 HttpJsonServiceUsageStub(ServiceUsageStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonServiceUsageCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonServiceUsageStub, 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 HttpJsonServiceUsageStub( + ServiceUsageStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings enableServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(enableServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings disableServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(disableServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getServiceTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getServiceMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchEnableServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchEnableServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listConsumerQuotaMetricsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listConsumerQuotaMetricsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getConsumerQuotaMetricTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getConsumerQuotaMetricMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getConsumerQuotaLimitTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getConsumerQuotaLimitMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createAdminOverrideTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createAdminOverrideMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateAdminOverrideTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateAdminOverrideMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteAdminOverrideTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteAdminOverrideMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listAdminOverridesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listAdminOverridesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + importAdminOverridesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importAdminOverridesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createConsumerOverrideTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createConsumerOverrideMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateConsumerOverrideTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateConsumerOverrideMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteConsumerOverrideTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteConsumerOverrideMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listConsumerOverridesTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listConsumerOverridesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + importConsumerOverridesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importConsumerOverridesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + generateServiceIdentityTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(generateServiceIdentityMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.enableServiceCallable = + callableFactory.createUnaryCallable( + enableServiceTransportSettings, settings.enableServiceSettings(), clientContext); + this.enableServiceOperationCallable = + callableFactory.createOperationCallable( + enableServiceTransportSettings, + settings.enableServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.disableServiceCallable = + callableFactory.createUnaryCallable( + disableServiceTransportSettings, settings.disableServiceSettings(), clientContext); + this.disableServiceOperationCallable = + callableFactory.createOperationCallable( + disableServiceTransportSettings, + settings.disableServiceOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.getServiceCallable = + callableFactory.createUnaryCallable( + getServiceTransportSettings, settings.getServiceSettings(), clientContext); + this.listServicesCallable = + callableFactory.createUnaryCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.listServicesPagedCallable = + callableFactory.createPagedCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.batchEnableServicesCallable = + callableFactory.createUnaryCallable( + batchEnableServicesTransportSettings, + settings.batchEnableServicesSettings(), + clientContext); + this.batchEnableServicesOperationCallable = + callableFactory.createOperationCallable( + batchEnableServicesTransportSettings, + settings.batchEnableServicesOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listConsumerQuotaMetricsCallable = + callableFactory.createUnaryCallable( + listConsumerQuotaMetricsTransportSettings, + settings.listConsumerQuotaMetricsSettings(), + clientContext); + this.listConsumerQuotaMetricsPagedCallable = + callableFactory.createPagedCallable( + listConsumerQuotaMetricsTransportSettings, + settings.listConsumerQuotaMetricsSettings(), + clientContext); + this.getConsumerQuotaMetricCallable = + callableFactory.createUnaryCallable( + getConsumerQuotaMetricTransportSettings, + settings.getConsumerQuotaMetricSettings(), + clientContext); + this.getConsumerQuotaLimitCallable = + callableFactory.createUnaryCallable( + getConsumerQuotaLimitTransportSettings, + settings.getConsumerQuotaLimitSettings(), + clientContext); + this.createAdminOverrideCallable = + callableFactory.createUnaryCallable( + createAdminOverrideTransportSettings, + settings.createAdminOverrideSettings(), + clientContext); + this.createAdminOverrideOperationCallable = + callableFactory.createOperationCallable( + createAdminOverrideTransportSettings, + settings.createAdminOverrideOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateAdminOverrideCallable = + callableFactory.createUnaryCallable( + updateAdminOverrideTransportSettings, + settings.updateAdminOverrideSettings(), + clientContext); + this.updateAdminOverrideOperationCallable = + callableFactory.createOperationCallable( + updateAdminOverrideTransportSettings, + settings.updateAdminOverrideOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteAdminOverrideCallable = + callableFactory.createUnaryCallable( + deleteAdminOverrideTransportSettings, + settings.deleteAdminOverrideSettings(), + clientContext); + this.deleteAdminOverrideOperationCallable = + callableFactory.createOperationCallable( + deleteAdminOverrideTransportSettings, + settings.deleteAdminOverrideOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listAdminOverridesCallable = + callableFactory.createUnaryCallable( + listAdminOverridesTransportSettings, + settings.listAdminOverridesSettings(), + clientContext); + this.listAdminOverridesPagedCallable = + callableFactory.createPagedCallable( + listAdminOverridesTransportSettings, + settings.listAdminOverridesSettings(), + clientContext); + this.importAdminOverridesCallable = + callableFactory.createUnaryCallable( + importAdminOverridesTransportSettings, + settings.importAdminOverridesSettings(), + clientContext); + this.importAdminOverridesOperationCallable = + callableFactory.createOperationCallable( + importAdminOverridesTransportSettings, + settings.importAdminOverridesOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.createConsumerOverrideCallable = + callableFactory.createUnaryCallable( + createConsumerOverrideTransportSettings, + settings.createConsumerOverrideSettings(), + clientContext); + this.createConsumerOverrideOperationCallable = + callableFactory.createOperationCallable( + createConsumerOverrideTransportSettings, + settings.createConsumerOverrideOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.updateConsumerOverrideCallable = + callableFactory.createUnaryCallable( + updateConsumerOverrideTransportSettings, + settings.updateConsumerOverrideSettings(), + clientContext); + this.updateConsumerOverrideOperationCallable = + callableFactory.createOperationCallable( + updateConsumerOverrideTransportSettings, + settings.updateConsumerOverrideOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.deleteConsumerOverrideCallable = + callableFactory.createUnaryCallable( + deleteConsumerOverrideTransportSettings, + settings.deleteConsumerOverrideSettings(), + clientContext); + this.deleteConsumerOverrideOperationCallable = + callableFactory.createOperationCallable( + deleteConsumerOverrideTransportSettings, + settings.deleteConsumerOverrideOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listConsumerOverridesCallable = + callableFactory.createUnaryCallable( + listConsumerOverridesTransportSettings, + settings.listConsumerOverridesSettings(), + clientContext); + this.listConsumerOverridesPagedCallable = + callableFactory.createPagedCallable( + listConsumerOverridesTransportSettings, + settings.listConsumerOverridesSettings(), + clientContext); + this.importConsumerOverridesCallable = + callableFactory.createUnaryCallable( + importConsumerOverridesTransportSettings, + settings.importConsumerOverridesSettings(), + clientContext); + this.importConsumerOverridesOperationCallable = + callableFactory.createOperationCallable( + importConsumerOverridesTransportSettings, + settings.importConsumerOverridesOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.generateServiceIdentityCallable = + callableFactory.createUnaryCallable( + generateServiceIdentityTransportSettings, + settings.generateServiceIdentitySettings(), + clientContext); + this.generateServiceIdentityOperationCallable = + callableFactory.createOperationCallable( + generateServiceIdentityTransportSettings, + settings.generateServiceIdentityOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(enableServiceMethodDescriptor); + methodDescriptors.add(disableServiceMethodDescriptor); + methodDescriptors.add(getServiceMethodDescriptor); + methodDescriptors.add(listServicesMethodDescriptor); + methodDescriptors.add(batchEnableServicesMethodDescriptor); + methodDescriptors.add(listConsumerQuotaMetricsMethodDescriptor); + methodDescriptors.add(getConsumerQuotaMetricMethodDescriptor); + methodDescriptors.add(getConsumerQuotaLimitMethodDescriptor); + methodDescriptors.add(createAdminOverrideMethodDescriptor); + methodDescriptors.add(updateAdminOverrideMethodDescriptor); + methodDescriptors.add(deleteAdminOverrideMethodDescriptor); + methodDescriptors.add(listAdminOverridesMethodDescriptor); + methodDescriptors.add(importAdminOverridesMethodDescriptor); + methodDescriptors.add(createConsumerOverrideMethodDescriptor); + methodDescriptors.add(updateConsumerOverrideMethodDescriptor); + methodDescriptors.add(deleteConsumerOverrideMethodDescriptor); + methodDescriptors.add(listConsumerOverridesMethodDescriptor); + methodDescriptors.add(importConsumerOverridesMethodDescriptor); + methodDescriptors.add(generateServiceIdentityMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable enableServiceCallable() { + return enableServiceCallable; + } + + @Override + public OperationCallable + enableServiceOperationCallable() { + return enableServiceOperationCallable; + } + + @Override + public UnaryCallable disableServiceCallable() { + return disableServiceCallable; + } + + @Override + public OperationCallable + disableServiceOperationCallable() { + return disableServiceOperationCallable; + } + + @Override + public UnaryCallable getServiceCallable() { + return getServiceCallable; + } + + @Override + public UnaryCallable listServicesCallable() { + return listServicesCallable; + } + + @Override + public UnaryCallable listServicesPagedCallable() { + return listServicesPagedCallable; + } + + @Override + public UnaryCallable batchEnableServicesCallable() { + return batchEnableServicesCallable; + } + + @Override + public OperationCallable + batchEnableServicesOperationCallable() { + return batchEnableServicesOperationCallable; + } + + @Override + public UnaryCallable + listConsumerQuotaMetricsCallable() { + return listConsumerQuotaMetricsCallable; + } + + @Override + public UnaryCallable + listConsumerQuotaMetricsPagedCallable() { + return listConsumerQuotaMetricsPagedCallable; + } + + @Override + public UnaryCallable + getConsumerQuotaMetricCallable() { + return getConsumerQuotaMetricCallable; + } + + @Override + public UnaryCallable + getConsumerQuotaLimitCallable() { + return getConsumerQuotaLimitCallable; + } + + @Override + public UnaryCallable createAdminOverrideCallable() { + return createAdminOverrideCallable; + } + + @Override + public OperationCallable + createAdminOverrideOperationCallable() { + return createAdminOverrideOperationCallable; + } + + @Override + public UnaryCallable updateAdminOverrideCallable() { + return updateAdminOverrideCallable; + } + + @Override + public OperationCallable + updateAdminOverrideOperationCallable() { + return updateAdminOverrideOperationCallable; + } + + @Override + public UnaryCallable deleteAdminOverrideCallable() { + return deleteAdminOverrideCallable; + } + + @Override + public OperationCallable + deleteAdminOverrideOperationCallable() { + return deleteAdminOverrideOperationCallable; + } + + @Override + public UnaryCallable + listAdminOverridesCallable() { + return listAdminOverridesCallable; + } + + @Override + public UnaryCallable + listAdminOverridesPagedCallable() { + return listAdminOverridesPagedCallable; + } + + @Override + public UnaryCallable importAdminOverridesCallable() { + return importAdminOverridesCallable; + } + + @Override + public OperationCallable< + ImportAdminOverridesRequest, ImportAdminOverridesResponse, ImportAdminOverridesMetadata> + importAdminOverridesOperationCallable() { + return importAdminOverridesOperationCallable; + } + + @Override + public UnaryCallable createConsumerOverrideCallable() { + return createConsumerOverrideCallable; + } + + @Override + public OperationCallable + createConsumerOverrideOperationCallable() { + return createConsumerOverrideOperationCallable; + } + + @Override + public UnaryCallable updateConsumerOverrideCallable() { + return updateConsumerOverrideCallable; + } + + @Override + public OperationCallable + updateConsumerOverrideOperationCallable() { + return updateConsumerOverrideOperationCallable; + } + + @Override + public UnaryCallable deleteConsumerOverrideCallable() { + return deleteConsumerOverrideCallable; + } + + @Override + public OperationCallable + deleteConsumerOverrideOperationCallable() { + return deleteConsumerOverrideOperationCallable; + } + + @Override + public UnaryCallable + listConsumerOverridesCallable() { + return listConsumerOverridesCallable; + } + + @Override + public UnaryCallable + listConsumerOverridesPagedCallable() { + return listConsumerOverridesPagedCallable; + } + + @Override + public UnaryCallable + importConsumerOverridesCallable() { + return importConsumerOverridesCallable; + } + + @Override + public OperationCallable< + ImportConsumerOverridesRequest, + ImportConsumerOverridesResponse, + ImportConsumerOverridesMetadata> + importConsumerOverridesOperationCallable() { + return importConsumerOverridesOperationCallable; + } + + @Override + public UnaryCallable + generateServiceIdentityCallable() { + return generateServiceIdentityCallable; + } + + @Override + public OperationCallable + generateServiceIdentityOperationCallable() { + return generateServiceIdentityOperationCallable; + } + + @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-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStub.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStub.java index a490b6ee2960..9b0615a038ac 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStub.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStub.java @@ -74,7 +74,11 @@ public abstract class ServiceUsageStub 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; } @Deprecated diff --git a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStubSettings.java b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStubSettings.java index cd28bced9e0f..df33899a9073 100644 --- a/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStubSettings.java +++ b/java-service-usage/google-cloud-service-usage/src/main/java/com/google/api/serviceusage/v1beta1/stub/ServiceUsageStubSettings.java @@ -31,6 +31,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; @@ -682,6 +685,11 @@ public ServiceUsageStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcServiceUsageStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonServiceUsageStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -714,18 +722,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(ServiceUsageStubSettings.class)) @@ -733,11 +748,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(ServiceUsageStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ServiceUsageStubSettings.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); @@ -1050,6 +1084,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 .enableServiceSettings() diff --git a/java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1/ServiceUsageClientHttpJsonTest.java b/java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1/ServiceUsageClientHttpJsonTest.java new file mode 100644 index 000000000000..f2392881ce12 --- /dev/null +++ b/java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1/ServiceUsageClientHttpJsonTest.java @@ -0,0 +1,410 @@ +/* + * 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.api.serviceusage.v1; + +import static com.google.api.serviceusage.v1.ServiceUsageClient.ListServicesPagedResponse; + +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.api.serviceusage.v1.stub.HttpJsonServiceUsageStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +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 ServiceUsageClientHttpJsonTest { + private static MockHttpService mockService; + private static ServiceUsageClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonServiceUsageStub.getMethodDescriptors(), + ServiceUsageSettings.getDefaultEndpoint()); + ServiceUsageSettings settings = + ServiceUsageSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + ServiceUsageSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ServiceUsageClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void enableServiceTest() throws Exception { + EnableServiceResponse expectedResponse = + EnableServiceResponse.newBuilder().setService(Service.newBuilder().build()).build(); + Operation resultOperation = + Operation.newBuilder() + .setName("enableServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + EnableServiceRequest request = + EnableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + + EnableServiceResponse actualResponse = client.enableServiceAsync(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 enableServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EnableServiceRequest request = + EnableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + client.enableServiceAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void disableServiceTest() throws Exception { + DisableServiceResponse expectedResponse = + DisableServiceResponse.newBuilder().setService(Service.newBuilder().build()).build(); + Operation resultOperation = + Operation.newBuilder() + .setName("disableServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + DisableServiceRequest request = + DisableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .setDisableDependentServices(true) + .build(); + + DisableServiceResponse actualResponse = client.disableServiceAsync(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 disableServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DisableServiceRequest request = + DisableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .setDisableDependentServices(true) + .build(); + client.disableServiceAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getServiceTest() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName("name3373707") + .setParent("parent-995424086") + .setConfig(ServiceConfig.newBuilder().build()) + .setState(State.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + GetServiceRequest request = + GetServiceRequest.newBuilder().setName("name-7410/name-7410/services/service-7410").build(); + + Service actualResponse = client.getService(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 getServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetServiceRequest request = + GetServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + client.getService(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listServicesTest() throws Exception { + Service responsesElement = Service.newBuilder().build(); + ListServicesResponse expectedResponse = + ListServicesResponse.newBuilder() + .setNextPageToken("") + .addAllServices(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + + ListServicesPagedResponse pagedListResponse = client.listServices(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getServicesList().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 listServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + client.listServices(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchEnableServicesTest() throws Exception { + BatchEnableServicesResponse expectedResponse = + BatchEnableServicesResponse.newBuilder() + .addAllServices(new ArrayList()) + .addAllFailures(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchEnableServicesTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + BatchEnableServicesRequest request = + BatchEnableServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .addAllServiceIds(new ArrayList()) + .build(); + + BatchEnableServicesResponse actualResponse = client.batchEnableServicesAsync(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 batchEnableServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchEnableServicesRequest request = + BatchEnableServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .addAllServiceIds(new ArrayList()) + .build(); + client.batchEnableServicesAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void batchGetServicesTest() throws Exception { + BatchGetServicesResponse expectedResponse = + BatchGetServicesResponse.newBuilder().addAllServices(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + BatchGetServicesRequest request = + BatchGetServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .addAllNames(new ArrayList()) + .build(); + + BatchGetServicesResponse actualResponse = client.batchGetServices(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 batchGetServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchGetServicesRequest request = + BatchGetServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .addAllNames(new ArrayList()) + .build(); + client.batchGetServices(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1beta1/ServiceUsageClientHttpJsonTest.java b/java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1beta1/ServiceUsageClientHttpJsonTest.java new file mode 100644 index 000000000000..b525f6b22f08 --- /dev/null +++ b/java-service-usage/google-cloud-service-usage/src/test/java/com/google/api/serviceusage/v1beta1/ServiceUsageClientHttpJsonTest.java @@ -0,0 +1,1225 @@ +/* + * 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.api.serviceusage.v1beta1; + +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListAdminOverridesPagedResponse; +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListConsumerOverridesPagedResponse; +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListConsumerQuotaMetricsPagedResponse; +import static com.google.api.serviceusage.v1beta1.ServiceUsageClient.ListServicesPagedResponse; + +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.api.serviceusage.v1beta1.stub.HttpJsonServiceUsageStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +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 ServiceUsageClientHttpJsonTest { + private static MockHttpService mockService; + private static ServiceUsageClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonServiceUsageStub.getMethodDescriptors(), + ServiceUsageSettings.getDefaultEndpoint()); + ServiceUsageSettings settings = + ServiceUsageSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + ServiceUsageSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ServiceUsageClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void enableServiceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("enableServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + EnableServiceRequest request = + EnableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + + client.enableServiceAsync(request).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 enableServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EnableServiceRequest request = + EnableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + client.enableServiceAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void disableServiceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("disableServiceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + DisableServiceRequest request = + DisableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + + client.disableServiceAsync(request).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 disableServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DisableServiceRequest request = + DisableServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + client.disableServiceAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void getServiceTest() throws Exception { + Service expectedResponse = + Service.newBuilder() + .setName("name3373707") + .setParent("parent-995424086") + .setConfig(ServiceConfig.newBuilder().build()) + .setState(State.forNumber(0)) + .build(); + mockService.addResponse(expectedResponse); + + GetServiceRequest request = + GetServiceRequest.newBuilder().setName("name-7410/name-7410/services/service-7410").build(); + + Service actualResponse = client.getService(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 getServiceExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetServiceRequest request = + GetServiceRequest.newBuilder() + .setName("name-7410/name-7410/services/service-7410") + .build(); + client.getService(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listServicesTest() throws Exception { + Service responsesElement = Service.newBuilder().build(); + ListServicesResponse expectedResponse = + ListServicesResponse.newBuilder() + .setNextPageToken("") + .addAllServices(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + + ListServicesPagedResponse pagedListResponse = client.listServices(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getServicesList().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 listServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + client.listServices(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchEnableServicesTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchEnableServicesTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + BatchEnableServicesRequest request = + BatchEnableServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .addAllServiceIds(new ArrayList()) + .build(); + + client.batchEnableServicesAsync(request).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 batchEnableServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchEnableServicesRequest request = + BatchEnableServicesRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .addAllServiceIds(new ArrayList()) + .build(); + client.batchEnableServicesAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listConsumerQuotaMetricsTest() throws Exception { + ConsumerQuotaMetric responsesElement = ConsumerQuotaMetric.newBuilder().build(); + ListConsumerQuotaMetricsResponse expectedResponse = + ListConsumerQuotaMetricsResponse.newBuilder() + .setNextPageToken("") + .addAllMetrics(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListConsumerQuotaMetricsRequest request = + ListConsumerQuotaMetricsRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setView(QuotaView.forNumber(0)) + .build(); + + ListConsumerQuotaMetricsPagedResponse pagedListResponse = + client.listConsumerQuotaMetrics(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMetricsList().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 listConsumerQuotaMetricsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListConsumerQuotaMetricsRequest request = + ListConsumerQuotaMetricsRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setView(QuotaView.forNumber(0)) + .build(); + client.listConsumerQuotaMetrics(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getConsumerQuotaMetricTest() throws Exception { + ConsumerQuotaMetric expectedResponse = + ConsumerQuotaMetric.newBuilder() + .setName("name3373707") + .setMetric("metric-1077545552") + .setDisplayName("displayName1714148973") + .addAllConsumerQuotaLimits(new ArrayList()) + .addAllDescendantConsumerQuotaLimits(new ArrayList()) + .setUnit("unit3594628") + .build(); + mockService.addResponse(expectedResponse); + + GetConsumerQuotaMetricRequest request = + GetConsumerQuotaMetricRequest.newBuilder() + .setName( + "name-5949/name-5949/services/service-5949/consumerQuotaMetrics/consumerQuotaMetric-5949") + .setView(QuotaView.forNumber(0)) + .build(); + + ConsumerQuotaMetric actualResponse = client.getConsumerQuotaMetric(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 getConsumerQuotaMetricExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetConsumerQuotaMetricRequest request = + GetConsumerQuotaMetricRequest.newBuilder() + .setName( + "name-5949/name-5949/services/service-5949/consumerQuotaMetrics/consumerQuotaMetric-5949") + .setView(QuotaView.forNumber(0)) + .build(); + client.getConsumerQuotaMetric(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getConsumerQuotaLimitTest() throws Exception { + ConsumerQuotaLimit expectedResponse = + ConsumerQuotaLimit.newBuilder() + .setName("name3373707") + .setMetric("metric-1077545552") + .setUnit("unit3594628") + .setIsPrecise(true) + .setAllowsAdminOverrides(true) + .addAllQuotaBuckets(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + GetConsumerQuotaLimitRequest request = + GetConsumerQuotaLimitRequest.newBuilder() + .setName( + "name-6379/name-6379/services/service-6379/consumerQuotaMetrics/consumerQuotaMetric-6379/limits/limit-6379") + .setView(QuotaView.forNumber(0)) + .build(); + + ConsumerQuotaLimit actualResponse = client.getConsumerQuotaLimit(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 getConsumerQuotaLimitExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetConsumerQuotaLimitRequest request = + GetConsumerQuotaLimitRequest.newBuilder() + .setName( + "name-6379/name-6379/services/service-6379/consumerQuotaMetrics/consumerQuotaMetric-6379/limits/limit-6379") + .setView(QuotaView.forNumber(0)) + .build(); + client.getConsumerQuotaLimit(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createAdminOverrideTest() throws Exception { + QuotaOverride expectedResponse = + QuotaOverride.newBuilder() + .setName("name3373707") + .setOverrideValue(-355006658) + .putAllDimensions(new HashMap()) + .setMetric("metric-1077545552") + .setUnit("unit3594628") + .setAdminOverrideAncestor("adminOverrideAncestor-1443674322") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createAdminOverrideTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + CreateAdminOverrideRequest request = + CreateAdminOverrideRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + + QuotaOverride actualResponse = client.createAdminOverrideAsync(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 createAdminOverrideExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CreateAdminOverrideRequest request = + CreateAdminOverrideRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + client.createAdminOverrideAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateAdminOverrideTest() throws Exception { + QuotaOverride expectedResponse = + QuotaOverride.newBuilder() + .setName("name3373707") + .setOverrideValue(-355006658) + .putAllDimensions(new HashMap()) + .setMetric("metric-1077545552") + .setUnit("unit3594628") + .setAdminOverrideAncestor("adminOverrideAncestor-1443674322") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateAdminOverrideTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + UpdateAdminOverrideRequest request = + UpdateAdminOverrideRequest.newBuilder() + .setName( + "name-9389/name-9389/services/service-9389/consumerQuotaMetrics/consumerQuotaMetric-9389/limits/limit-9389/adminOverrides/adminOverride-9389") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .setUpdateMask(FieldMask.newBuilder().build()) + .addAllForceOnly(new ArrayList()) + .build(); + + QuotaOverride actualResponse = client.updateAdminOverrideAsync(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 updateAdminOverrideExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UpdateAdminOverrideRequest request = + UpdateAdminOverrideRequest.newBuilder() + .setName( + "name-9389/name-9389/services/service-9389/consumerQuotaMetrics/consumerQuotaMetric-9389/limits/limit-9389/adminOverrides/adminOverride-9389") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .setUpdateMask(FieldMask.newBuilder().build()) + .addAllForceOnly(new ArrayList()) + .build(); + client.updateAdminOverrideAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteAdminOverrideTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteAdminOverrideTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + DeleteAdminOverrideRequest request = + DeleteAdminOverrideRequest.newBuilder() + .setName( + "name-9389/name-9389/services/service-9389/consumerQuotaMetrics/consumerQuotaMetric-9389/limits/limit-9389/adminOverrides/adminOverride-9389") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + + client.deleteAdminOverrideAsync(request).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 deleteAdminOverrideExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DeleteAdminOverrideRequest request = + DeleteAdminOverrideRequest.newBuilder() + .setName( + "name-9389/name-9389/services/service-9389/consumerQuotaMetrics/consumerQuotaMetric-9389/limits/limit-9389/adminOverrides/adminOverride-9389") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + client.deleteAdminOverrideAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listAdminOverridesTest() throws Exception { + QuotaOverride responsesElement = QuotaOverride.newBuilder().build(); + ListAdminOverridesResponse expectedResponse = + ListAdminOverridesResponse.newBuilder() + .setNextPageToken("") + .addAllOverrides(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListAdminOverridesRequest request = + ListAdminOverridesRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListAdminOverridesPagedResponse pagedListResponse = client.listAdminOverrides(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getOverridesList().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 listAdminOverridesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListAdminOverridesRequest request = + ListAdminOverridesRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listAdminOverrides(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void importAdminOverridesTest() throws Exception { + ImportAdminOverridesResponse expectedResponse = + ImportAdminOverridesResponse.newBuilder() + .addAllOverrides(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importAdminOverridesTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ImportAdminOverridesRequest request = + ImportAdminOverridesRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + + ImportAdminOverridesResponse actualResponse = client.importAdminOverridesAsync(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 importAdminOverridesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportAdminOverridesRequest request = + ImportAdminOverridesRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + client.importAdminOverridesAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createConsumerOverrideTest() throws Exception { + QuotaOverride expectedResponse = + QuotaOverride.newBuilder() + .setName("name3373707") + .setOverrideValue(-355006658) + .putAllDimensions(new HashMap()) + .setMetric("metric-1077545552") + .setUnit("unit3594628") + .setAdminOverrideAncestor("adminOverrideAncestor-1443674322") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createConsumerOverrideTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + CreateConsumerOverrideRequest request = + CreateConsumerOverrideRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + + QuotaOverride actualResponse = client.createConsumerOverrideAsync(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 createConsumerOverrideExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CreateConsumerOverrideRequest request = + CreateConsumerOverrideRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + client.createConsumerOverrideAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void updateConsumerOverrideTest() throws Exception { + QuotaOverride expectedResponse = + QuotaOverride.newBuilder() + .setName("name3373707") + .setOverrideValue(-355006658) + .putAllDimensions(new HashMap()) + .setMetric("metric-1077545552") + .setUnit("unit3594628") + .setAdminOverrideAncestor("adminOverrideAncestor-1443674322") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateConsumerOverrideTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + UpdateConsumerOverrideRequest request = + UpdateConsumerOverrideRequest.newBuilder() + .setName( + "name-4498/name-4498/services/service-4498/consumerQuotaMetrics/consumerQuotaMetric-4498/limits/limit-4498/consumerOverrides/consumerOverride-4498") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .setUpdateMask(FieldMask.newBuilder().build()) + .addAllForceOnly(new ArrayList()) + .build(); + + QuotaOverride actualResponse = client.updateConsumerOverrideAsync(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 updateConsumerOverrideExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + UpdateConsumerOverrideRequest request = + UpdateConsumerOverrideRequest.newBuilder() + .setName( + "name-4498/name-4498/services/service-4498/consumerQuotaMetrics/consumerQuotaMetric-4498/limits/limit-4498/consumerOverrides/consumerOverride-4498") + .setOverride(QuotaOverride.newBuilder().build()) + .setForce(true) + .setUpdateMask(FieldMask.newBuilder().build()) + .addAllForceOnly(new ArrayList()) + .build(); + client.updateConsumerOverrideAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteConsumerOverrideTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteConsumerOverrideTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + DeleteConsumerOverrideRequest request = + DeleteConsumerOverrideRequest.newBuilder() + .setName( + "name-4498/name-4498/services/service-4498/consumerQuotaMetrics/consumerQuotaMetric-4498/limits/limit-4498/consumerOverrides/consumerOverride-4498") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + + client.deleteConsumerOverrideAsync(request).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 deleteConsumerOverrideExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + DeleteConsumerOverrideRequest request = + DeleteConsumerOverrideRequest.newBuilder() + .setName( + "name-4498/name-4498/services/service-4498/consumerQuotaMetrics/consumerQuotaMetric-4498/limits/limit-4498/consumerOverrides/consumerOverride-4498") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + client.deleteConsumerOverrideAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listConsumerOverridesTest() throws Exception { + QuotaOverride responsesElement = QuotaOverride.newBuilder().build(); + ListConsumerOverridesResponse expectedResponse = + ListConsumerOverridesResponse.newBuilder() + .setNextPageToken("") + .addAllOverrides(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListConsumerOverridesRequest request = + ListConsumerOverridesRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListConsumerOverridesPagedResponse pagedListResponse = client.listConsumerOverrides(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getOverridesList().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 listConsumerOverridesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListConsumerOverridesRequest request = + ListConsumerOverridesRequest.newBuilder() + .setParent( + "parent-8356/parent-8356/services/service-8356/consumerQuotaMetrics/consumerQuotaMetric-8356/limits/limit-8356") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listConsumerOverrides(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void importConsumerOverridesTest() throws Exception { + ImportConsumerOverridesResponse expectedResponse = + ImportConsumerOverridesResponse.newBuilder() + .addAllOverrides(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importConsumerOverridesTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ImportConsumerOverridesRequest request = + ImportConsumerOverridesRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + + ImportConsumerOverridesResponse actualResponse = + client.importConsumerOverridesAsync(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 importConsumerOverridesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ImportConsumerOverridesRequest request = + ImportConsumerOverridesRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .setForce(true) + .addAllForceOnly(new ArrayList()) + .build(); + client.importConsumerOverridesAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void generateServiceIdentityTest() throws Exception { + ServiceIdentity expectedResponse = + ServiceIdentity.newBuilder() + .setEmail("email96619420") + .setUniqueId("uniqueId-294460212") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("generateServiceIdentityTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GenerateServiceIdentityRequest request = + GenerateServiceIdentityRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .build(); + + ServiceIdentity actualResponse = client.generateServiceIdentityAsync(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 generateServiceIdentityExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GenerateServiceIdentityRequest request = + GenerateServiceIdentityRequest.newBuilder() + .setParent("parent-2637/parent-2637/services/service-2637") + .build(); + client.generateServiceIdentityAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +}