From 3a06bdf6ca4f1ac35b0721f15e2f8a7421185b9f Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 28 Jun 2022 16:40:45 -0700 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#690) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): upgrade gapic-generator-java to 2.8.0 and update gax-java to 2.18.1 PiperOrigin-RevId: 450543911 Source-Link: https://github.com/googleapis/googleapis/commit/55283447ab72f10b6c2571d770af0498b593e84f Source-Link: https://github.com/googleapis/googleapis-gen/commit/9f6775cab1958982b88967a43e5e806af0f135db Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiOWY2Nzc1Y2FiMTk1ODk4MmI4ODk2N2E0M2U1ZTgwNmFmMGYxMzVkYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 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: Enable REST transport for most of Java and Go clients PiperOrigin-RevId: 456641589 Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update pom.xml Co-authored-by: Owl Bot Co-authored-by: Neenu Shaji --- google-cloud-tasks/pom.xml | 16 + .../cloud/tasks/v2/CloudTasksClient.java | 22 +- .../cloud/tasks/v2/CloudTasksSettings.java | 23 +- .../tasks/v2/stub/CloudTasksStubSettings.java | 54 +- .../HttpJsonCloudTasksCallableFactory.java | 105 + .../tasks/v2/stub/HttpJsonCloudTasksStub.java | 982 ++++++++ .../cloud/tasks/v2beta2/CloudTasksClient.java | 21 +- .../tasks/v2beta2/CloudTasksSettings.java | 23 +- .../v2beta2/stub/CloudTasksStubSettings.java | 54 +- .../HttpJsonCloudTasksCallableFactory.java | 105 + .../v2beta2/stub/HttpJsonCloudTasksStub.java | 1191 ++++++++++ .../cloud/tasks/v2beta3/CloudTasksClient.java | 21 +- .../tasks/v2beta3/CloudTasksSettings.java | 23 +- .../v2beta3/stub/CloudTasksStubSettings.java | 54 +- .../HttpJsonCloudTasksCallableFactory.java | 105 + .../v2beta3/stub/HttpJsonCloudTasksStub.java | 984 +++++++++ .../v2/CloudTasksClientHttpJsonTest.java | 1602 ++++++++++++++ .../v2beta2/CloudTasksClientHttpJsonTest.java | 1966 +++++++++++++++++ .../v2beta3/CloudTasksClientHttpJsonTest.java | 1628 ++++++++++++++ 19 files changed, 8945 insertions(+), 34 deletions(-) create mode 100644 google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksCallableFactory.java create mode 100644 google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksStub.java create mode 100644 google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksCallableFactory.java create mode 100644 google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksStub.java create mode 100644 google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksCallableFactory.java create mode 100644 google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksStub.java create mode 100644 google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2/CloudTasksClientHttpJsonTest.java create mode 100644 google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta2/CloudTasksClientHttpJsonTest.java create mode 100644 google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta3/CloudTasksClientHttpJsonTest.java diff --git a/google-cloud-tasks/pom.xml b/google-cloud-tasks/pom.xml index be33188c..c6817d84 100644 --- a/google-cloud-tasks/pom.xml +++ b/google-cloud-tasks/pom.xml @@ -66,6 +66,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -102,12 +106,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksClient.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksClient.java index 4d289ca9..cf1c53d1 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksClient.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksClient.java @@ -18,7 +18,6 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; -import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -106,6 +105,20 @@ * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings); * } * + *

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.
+ * CloudTasksSettings cloudTasksSettings =
+ *     CloudTasksSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudTasksSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") @@ -130,7 +143,6 @@ public static final CloudTasksClient create(CloudTasksSettings settings) throws * Constructs an instance of CloudTasksClient, using the given stub for making calls. This is for * advanced usage - prefer using create(CloudTasksSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final CloudTasksClient create(CloudTasksStub stub) { return new CloudTasksClient(stub); } @@ -144,7 +156,6 @@ protected CloudTasksClient(CloudTasksSettings settings) throws IOException { this.stub = ((CloudTasksStubSettings) settings.getStubSettings()).createStub(); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected CloudTasksClient(CloudTasksStub stub) { this.settings = null; this.stub = stub; @@ -154,7 +165,6 @@ public final CloudTasksSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub getStub() { return stub; } @@ -300,7 +310,7 @@ public final UnaryCallable listQueue * .build(); * while (true) { * ListQueuesResponse response = cloudTasksClient.listQueuesCallable().call(request); - * for (Queue element : response.getResponsesList()) { + * for (Queue element : response.getQueuesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1785,7 +1795,7 @@ public final UnaryCallable listTasksPa * .build(); * while (true) { * ListTasksResponse response = cloudTasksClient.listTasksCallable().call(request); - * for (Task element : response.getResponsesList()) { + * for (Task element : response.getTasksList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksSettings.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksSettings.java index 433cfa77..5ba02bdf 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksSettings.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/CloudTasksSettings.java @@ -24,6 +24,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; @@ -184,11 +185,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudTasksStubSettings.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 CloudTasksStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudTasksStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudTasksStubSettings.defaultTransportChannelProvider(); } @@ -198,11 +206,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudTasksStubSettings.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); @@ -240,6 +254,11 @@ private static Builder createDefault() { return new Builder(CloudTasksStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudTasksStubSettings.newHttpJsonBuilder()); + } + public CloudTasksStubSettings.Builder getStubSettingsBuilder() { return ((CloudTasksStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/CloudTasksStubSettings.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/CloudTasksStubSettings.java index fcc4bf86..917761b9 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/CloudTasksStubSettings.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/CloudTasksStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -321,13 +324,17 @@ public UnaryCallSettings runTaskSettings() { return runTaskSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudTasksStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudTasksStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -360,18 +367,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(CloudTasksStubSettings.class)) @@ -379,11 +393,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(CloudTasksStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudTasksStubSettings.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); @@ -580,6 +613,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 .listQueuesSettings() diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksCallableFactory.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksCallableFactory.java new file mode 100644 index 00000000..df93d9fd --- /dev/null +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2.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 CloudTasks service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudTasksCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksStub.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksStub.java new file mode 100644 index 00000000..79109ceb --- /dev/null +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2/stub/HttpJsonCloudTasksStub.java @@ -0,0 +1,982 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2.stub; + +import static com.google.cloud.tasks.v2.CloudTasksClient.ListQueuesPagedResponse; +import static com.google.cloud.tasks.v2.CloudTasksClient.ListTasksPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.tasks.v2.CreateQueueRequest; +import com.google.cloud.tasks.v2.CreateTaskRequest; +import com.google.cloud.tasks.v2.DeleteQueueRequest; +import com.google.cloud.tasks.v2.DeleteTaskRequest; +import com.google.cloud.tasks.v2.GetQueueRequest; +import com.google.cloud.tasks.v2.GetTaskRequest; +import com.google.cloud.tasks.v2.ListQueuesRequest; +import com.google.cloud.tasks.v2.ListQueuesResponse; +import com.google.cloud.tasks.v2.ListTasksRequest; +import com.google.cloud.tasks.v2.ListTasksResponse; +import com.google.cloud.tasks.v2.PauseQueueRequest; +import com.google.cloud.tasks.v2.PurgeQueueRequest; +import com.google.cloud.tasks.v2.Queue; +import com.google.cloud.tasks.v2.ResumeQueueRequest; +import com.google.cloud.tasks.v2.RunTaskRequest; +import com.google.cloud.tasks.v2.Task; +import com.google.cloud.tasks.v2.UpdateQueueRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.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 CloudTasks service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudTasksStub extends CloudTasksStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listQueuesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/ListQueues") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*}/queues", + 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(ListQueuesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/GetQueue") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*}", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/CreateQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*}/queues", + 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("queue", request.getQueue())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/UpdateQueue") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{queue.name=projects/*/locations/*/queues/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "queue.name", request.getQueue().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("queue", request.getQueue())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/DeleteQueue") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor purgeQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/PurgeQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*}:purge", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor pauseQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/PauseQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*}:pause", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor resumeQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/ResumeQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*}:resume", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/GetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{resource=projects/*/locations/*/queues/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{resource=projects/*/locations/*/queues/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{resource=projects/*/locations/*/queues/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listTasksMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/ListTasks") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*/queues/*}/tasks", + 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, "responseView", request.getResponseView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListTasksResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/GetTask") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*/tasks/*}", + 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, "responseView", request.getResponseView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/CreateTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*/queues/*}/tasks", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/DeleteTask") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*/tasks/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor runTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2.CloudTasks/RunTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/queues/*/tasks/*}:run", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listQueuesCallable; + private final UnaryCallable listQueuesPagedCallable; + private final UnaryCallable getQueueCallable; + private final UnaryCallable createQueueCallable; + private final UnaryCallable updateQueueCallable; + private final UnaryCallable deleteQueueCallable; + private final UnaryCallable purgeQueueCallable; + private final UnaryCallable pauseQueueCallable; + private final UnaryCallable resumeQueueCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + private final UnaryCallable listTasksCallable; + private final UnaryCallable listTasksPagedCallable; + private final UnaryCallable getTaskCallable; + private final UnaryCallable createTaskCallable; + private final UnaryCallable deleteTaskCallable; + private final UnaryCallable runTaskCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudTasksStub create(CloudTasksStubSettings settings) + throws IOException { + return new HttpJsonCloudTasksStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudTasksStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudTasksStub( + CloudTasksStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudTasksStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudTasksStub( + CloudTasksStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudTasksStub, 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 HttpJsonCloudTasksStub(CloudTasksStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudTasksCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudTasksStub, 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 HttpJsonCloudTasksStub( + CloudTasksStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listQueuesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listQueuesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings purgeQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(purgeQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings pauseQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pauseQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings resumeQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(resumeQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listTasksTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listTasksMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings runTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(runTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listQueuesCallable = + callableFactory.createUnaryCallable( + listQueuesTransportSettings, settings.listQueuesSettings(), clientContext); + this.listQueuesPagedCallable = + callableFactory.createPagedCallable( + listQueuesTransportSettings, settings.listQueuesSettings(), clientContext); + this.getQueueCallable = + callableFactory.createUnaryCallable( + getQueueTransportSettings, settings.getQueueSettings(), clientContext); + this.createQueueCallable = + callableFactory.createUnaryCallable( + createQueueTransportSettings, settings.createQueueSettings(), clientContext); + this.updateQueueCallable = + callableFactory.createUnaryCallable( + updateQueueTransportSettings, settings.updateQueueSettings(), clientContext); + this.deleteQueueCallable = + callableFactory.createUnaryCallable( + deleteQueueTransportSettings, settings.deleteQueueSettings(), clientContext); + this.purgeQueueCallable = + callableFactory.createUnaryCallable( + purgeQueueTransportSettings, settings.purgeQueueSettings(), clientContext); + this.pauseQueueCallable = + callableFactory.createUnaryCallable( + pauseQueueTransportSettings, settings.pauseQueueSettings(), clientContext); + this.resumeQueueCallable = + callableFactory.createUnaryCallable( + resumeQueueTransportSettings, settings.resumeQueueSettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + this.listTasksCallable = + callableFactory.createUnaryCallable( + listTasksTransportSettings, settings.listTasksSettings(), clientContext); + this.listTasksPagedCallable = + callableFactory.createPagedCallable( + listTasksTransportSettings, settings.listTasksSettings(), clientContext); + this.getTaskCallable = + callableFactory.createUnaryCallable( + getTaskTransportSettings, settings.getTaskSettings(), clientContext); + this.createTaskCallable = + callableFactory.createUnaryCallable( + createTaskTransportSettings, settings.createTaskSettings(), clientContext); + this.deleteTaskCallable = + callableFactory.createUnaryCallable( + deleteTaskTransportSettings, settings.deleteTaskSettings(), clientContext); + this.runTaskCallable = + callableFactory.createUnaryCallable( + runTaskTransportSettings, settings.runTaskSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listQueuesMethodDescriptor); + methodDescriptors.add(getQueueMethodDescriptor); + methodDescriptors.add(createQueueMethodDescriptor); + methodDescriptors.add(updateQueueMethodDescriptor); + methodDescriptors.add(deleteQueueMethodDescriptor); + methodDescriptors.add(purgeQueueMethodDescriptor); + methodDescriptors.add(pauseQueueMethodDescriptor); + methodDescriptors.add(resumeQueueMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + methodDescriptors.add(listTasksMethodDescriptor); + methodDescriptors.add(getTaskMethodDescriptor); + methodDescriptors.add(createTaskMethodDescriptor); + methodDescriptors.add(deleteTaskMethodDescriptor); + methodDescriptors.add(runTaskMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listQueuesCallable() { + return listQueuesCallable; + } + + @Override + public UnaryCallable listQueuesPagedCallable() { + return listQueuesPagedCallable; + } + + @Override + public UnaryCallable getQueueCallable() { + return getQueueCallable; + } + + @Override + public UnaryCallable createQueueCallable() { + return createQueueCallable; + } + + @Override + public UnaryCallable updateQueueCallable() { + return updateQueueCallable; + } + + @Override + public UnaryCallable deleteQueueCallable() { + return deleteQueueCallable; + } + + @Override + public UnaryCallable purgeQueueCallable() { + return purgeQueueCallable; + } + + @Override + public UnaryCallable pauseQueueCallable() { + return pauseQueueCallable; + } + + @Override + public UnaryCallable resumeQueueCallable() { + return resumeQueueCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public UnaryCallable listTasksCallable() { + return listTasksCallable; + } + + @Override + public UnaryCallable listTasksPagedCallable() { + return listTasksPagedCallable; + } + + @Override + public UnaryCallable getTaskCallable() { + return getTaskCallable; + } + + @Override + public UnaryCallable createTaskCallable() { + return createTaskCallable; + } + + @Override + public UnaryCallable deleteTaskCallable() { + return deleteTaskCallable; + } + + @Override + public UnaryCallable runTaskCallable() { + return runTaskCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksClient.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksClient.java index 09c3408d..2fb0f905 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksClient.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksClient.java @@ -108,6 +108,20 @@ * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings); * } * + *

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.
+ * CloudTasksSettings cloudTasksSettings =
+ *     CloudTasksSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudTasksSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -133,7 +147,6 @@ public static final CloudTasksClient create(CloudTasksSettings settings) throws * Constructs an instance of CloudTasksClient, using the given stub for making calls. This is for * advanced usage - prefer using create(CloudTasksSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final CloudTasksClient create(CloudTasksStub stub) { return new CloudTasksClient(stub); } @@ -147,7 +160,6 @@ protected CloudTasksClient(CloudTasksSettings settings) throws IOException { this.stub = ((CloudTasksStubSettings) settings.getStubSettings()).createStub(); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected CloudTasksClient(CloudTasksStub stub) { this.settings = null; this.stub = stub; @@ -157,7 +169,6 @@ public final CloudTasksSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub getStub() { return stub; } @@ -306,7 +317,7 @@ public final UnaryCallable listQueue * .build(); * while (true) { * ListQueuesResponse response = cloudTasksClient.listQueuesCallable().call(request); - * for (Queue element : response.getResponsesList()) { + * for (Queue element : response.getQueuesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1797,7 +1808,7 @@ public final UnaryCallable listTasksPa * .build(); * while (true) { * ListTasksResponse response = cloudTasksClient.listTasksCallable().call(request); - * for (Task element : response.getResponsesList()) { + * for (Task element : response.getTasksList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksSettings.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksSettings.java index 3f9c9be6..88d405e7 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksSettings.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/CloudTasksSettings.java @@ -24,6 +24,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; @@ -205,11 +206,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudTasksStubSettings.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 CloudTasksStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudTasksStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudTasksStubSettings.defaultTransportChannelProvider(); } @@ -219,11 +227,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudTasksStubSettings.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); @@ -261,6 +275,11 @@ private static Builder createDefault() { return new Builder(CloudTasksStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudTasksStubSettings.newHttpJsonBuilder()); + } + public CloudTasksStubSettings.Builder getStubSettingsBuilder() { return ((CloudTasksStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/CloudTasksStubSettings.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/CloudTasksStubSettings.java index 59a0f2ba..27411d78 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/CloudTasksStubSettings.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/CloudTasksStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -351,13 +354,17 @@ public UnaryCallSettings runTaskSettings() { return runTaskSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudTasksStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudTasksStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -390,18 +397,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(CloudTasksStubSettings.class)) @@ -409,11 +423,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(CloudTasksStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudTasksStubSettings.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); @@ -635,6 +668,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 .listQueuesSettings() diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksCallableFactory.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksCallableFactory.java new file mode 100644 index 00000000..3ea5df3e --- /dev/null +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2beta2.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 CloudTasks service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudTasksCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksStub.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksStub.java new file mode 100644 index 00000000..268878f2 --- /dev/null +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta2/stub/HttpJsonCloudTasksStub.java @@ -0,0 +1,1191 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2beta2.stub; + +import static com.google.cloud.tasks.v2beta2.CloudTasksClient.ListQueuesPagedResponse; +import static com.google.cloud.tasks.v2beta2.CloudTasksClient.ListTasksPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.tasks.v2beta2.AcknowledgeTaskRequest; +import com.google.cloud.tasks.v2beta2.CancelLeaseRequest; +import com.google.cloud.tasks.v2beta2.CreateQueueRequest; +import com.google.cloud.tasks.v2beta2.CreateTaskRequest; +import com.google.cloud.tasks.v2beta2.DeleteQueueRequest; +import com.google.cloud.tasks.v2beta2.DeleteTaskRequest; +import com.google.cloud.tasks.v2beta2.GetQueueRequest; +import com.google.cloud.tasks.v2beta2.GetTaskRequest; +import com.google.cloud.tasks.v2beta2.LeaseTasksRequest; +import com.google.cloud.tasks.v2beta2.LeaseTasksResponse; +import com.google.cloud.tasks.v2beta2.ListQueuesRequest; +import com.google.cloud.tasks.v2beta2.ListQueuesResponse; +import com.google.cloud.tasks.v2beta2.ListTasksRequest; +import com.google.cloud.tasks.v2beta2.ListTasksResponse; +import com.google.cloud.tasks.v2beta2.PauseQueueRequest; +import com.google.cloud.tasks.v2beta2.PurgeQueueRequest; +import com.google.cloud.tasks.v2beta2.Queue; +import com.google.cloud.tasks.v2beta2.RenewLeaseRequest; +import com.google.cloud.tasks.v2beta2.ResumeQueueRequest; +import com.google.cloud.tasks.v2beta2.RunTaskRequest; +import com.google.cloud.tasks.v2beta2.Task; +import com.google.cloud.tasks.v2beta2.UpdateQueueRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.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 CloudTasks service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudTasksStub extends CloudTasksStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listQueuesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/ListQueues") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{parent=projects/*/locations/*}/queues", + 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()); + serializer.putQueryParam(fields, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListQueuesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/GetQueue") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*}", + 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, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/CreateQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{parent=projects/*/locations/*}/queues", + 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("queue", request.getQueue())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/UpdateQueue") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{queue.name=projects/*/locations/*/queues/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "queue.name", request.getQueue().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("queue", request.getQueue())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/DeleteQueue") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor purgeQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/PurgeQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*}:purge", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor pauseQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/PauseQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*}:pause", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor resumeQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/ResumeQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*}:resume", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/GetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{resource=projects/*/locations/*/queues/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{resource=projects/*/locations/*/queues/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{resource=projects/*/locations/*/queues/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listTasksMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/ListTasks") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks", + 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, "responseView", request.getResponseView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListTasksResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/GetTask") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}", + 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, "responseView", request.getResponseView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/CreateTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/DeleteTask") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + leaseTasksMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/LeaseTasks") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{parent=projects/*/locations/*/queues/*}/tasks:lease", + 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(LeaseTasksResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + acknowledgeTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/AcknowledgeTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:acknowledge", + 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(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor renewLeaseMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/RenewLease") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:renewLease", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor cancelLeaseMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/CancelLease") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:cancelLease", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor runTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta2.CloudTasks/RunTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta2/{name=projects/*/locations/*/queues/*/tasks/*}:run", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listQueuesCallable; + private final UnaryCallable listQueuesPagedCallable; + private final UnaryCallable getQueueCallable; + private final UnaryCallable createQueueCallable; + private final UnaryCallable updateQueueCallable; + private final UnaryCallable deleteQueueCallable; + private final UnaryCallable purgeQueueCallable; + private final UnaryCallable pauseQueueCallable; + private final UnaryCallable resumeQueueCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + private final UnaryCallable listTasksCallable; + private final UnaryCallable listTasksPagedCallable; + private final UnaryCallable getTaskCallable; + private final UnaryCallable createTaskCallable; + private final UnaryCallable deleteTaskCallable; + private final UnaryCallable leaseTasksCallable; + private final UnaryCallable acknowledgeTaskCallable; + private final UnaryCallable renewLeaseCallable; + private final UnaryCallable cancelLeaseCallable; + private final UnaryCallable runTaskCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudTasksStub create(CloudTasksStubSettings settings) + throws IOException { + return new HttpJsonCloudTasksStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudTasksStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudTasksStub( + CloudTasksStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudTasksStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudTasksStub( + CloudTasksStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudTasksStub, 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 HttpJsonCloudTasksStub(CloudTasksStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudTasksCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudTasksStub, 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 HttpJsonCloudTasksStub( + CloudTasksStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listQueuesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listQueuesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings purgeQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(purgeQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings pauseQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pauseQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings resumeQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(resumeQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listTasksTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listTasksMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings leaseTasksTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(leaseTasksMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings acknowledgeTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(acknowledgeTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings renewLeaseTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(renewLeaseMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings cancelLeaseTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(cancelLeaseMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings runTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(runTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listQueuesCallable = + callableFactory.createUnaryCallable( + listQueuesTransportSettings, settings.listQueuesSettings(), clientContext); + this.listQueuesPagedCallable = + callableFactory.createPagedCallable( + listQueuesTransportSettings, settings.listQueuesSettings(), clientContext); + this.getQueueCallable = + callableFactory.createUnaryCallable( + getQueueTransportSettings, settings.getQueueSettings(), clientContext); + this.createQueueCallable = + callableFactory.createUnaryCallable( + createQueueTransportSettings, settings.createQueueSettings(), clientContext); + this.updateQueueCallable = + callableFactory.createUnaryCallable( + updateQueueTransportSettings, settings.updateQueueSettings(), clientContext); + this.deleteQueueCallable = + callableFactory.createUnaryCallable( + deleteQueueTransportSettings, settings.deleteQueueSettings(), clientContext); + this.purgeQueueCallable = + callableFactory.createUnaryCallable( + purgeQueueTransportSettings, settings.purgeQueueSettings(), clientContext); + this.pauseQueueCallable = + callableFactory.createUnaryCallable( + pauseQueueTransportSettings, settings.pauseQueueSettings(), clientContext); + this.resumeQueueCallable = + callableFactory.createUnaryCallable( + resumeQueueTransportSettings, settings.resumeQueueSettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + this.listTasksCallable = + callableFactory.createUnaryCallable( + listTasksTransportSettings, settings.listTasksSettings(), clientContext); + this.listTasksPagedCallable = + callableFactory.createPagedCallable( + listTasksTransportSettings, settings.listTasksSettings(), clientContext); + this.getTaskCallable = + callableFactory.createUnaryCallable( + getTaskTransportSettings, settings.getTaskSettings(), clientContext); + this.createTaskCallable = + callableFactory.createUnaryCallable( + createTaskTransportSettings, settings.createTaskSettings(), clientContext); + this.deleteTaskCallable = + callableFactory.createUnaryCallable( + deleteTaskTransportSettings, settings.deleteTaskSettings(), clientContext); + this.leaseTasksCallable = + callableFactory.createUnaryCallable( + leaseTasksTransportSettings, settings.leaseTasksSettings(), clientContext); + this.acknowledgeTaskCallable = + callableFactory.createUnaryCallable( + acknowledgeTaskTransportSettings, settings.acknowledgeTaskSettings(), clientContext); + this.renewLeaseCallable = + callableFactory.createUnaryCallable( + renewLeaseTransportSettings, settings.renewLeaseSettings(), clientContext); + this.cancelLeaseCallable = + callableFactory.createUnaryCallable( + cancelLeaseTransportSettings, settings.cancelLeaseSettings(), clientContext); + this.runTaskCallable = + callableFactory.createUnaryCallable( + runTaskTransportSettings, settings.runTaskSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listQueuesMethodDescriptor); + methodDescriptors.add(getQueueMethodDescriptor); + methodDescriptors.add(createQueueMethodDescriptor); + methodDescriptors.add(updateQueueMethodDescriptor); + methodDescriptors.add(deleteQueueMethodDescriptor); + methodDescriptors.add(purgeQueueMethodDescriptor); + methodDescriptors.add(pauseQueueMethodDescriptor); + methodDescriptors.add(resumeQueueMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + methodDescriptors.add(listTasksMethodDescriptor); + methodDescriptors.add(getTaskMethodDescriptor); + methodDescriptors.add(createTaskMethodDescriptor); + methodDescriptors.add(deleteTaskMethodDescriptor); + methodDescriptors.add(leaseTasksMethodDescriptor); + methodDescriptors.add(acknowledgeTaskMethodDescriptor); + methodDescriptors.add(renewLeaseMethodDescriptor); + methodDescriptors.add(cancelLeaseMethodDescriptor); + methodDescriptors.add(runTaskMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listQueuesCallable() { + return listQueuesCallable; + } + + @Override + public UnaryCallable listQueuesPagedCallable() { + return listQueuesPagedCallable; + } + + @Override + public UnaryCallable getQueueCallable() { + return getQueueCallable; + } + + @Override + public UnaryCallable createQueueCallable() { + return createQueueCallable; + } + + @Override + public UnaryCallable updateQueueCallable() { + return updateQueueCallable; + } + + @Override + public UnaryCallable deleteQueueCallable() { + return deleteQueueCallable; + } + + @Override + public UnaryCallable purgeQueueCallable() { + return purgeQueueCallable; + } + + @Override + public UnaryCallable pauseQueueCallable() { + return pauseQueueCallable; + } + + @Override + public UnaryCallable resumeQueueCallable() { + return resumeQueueCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public UnaryCallable listTasksCallable() { + return listTasksCallable; + } + + @Override + public UnaryCallable listTasksPagedCallable() { + return listTasksPagedCallable; + } + + @Override + public UnaryCallable getTaskCallable() { + return getTaskCallable; + } + + @Override + public UnaryCallable createTaskCallable() { + return createTaskCallable; + } + + @Override + public UnaryCallable deleteTaskCallable() { + return deleteTaskCallable; + } + + @Override + public UnaryCallable leaseTasksCallable() { + return leaseTasksCallable; + } + + @Override + public UnaryCallable acknowledgeTaskCallable() { + return acknowledgeTaskCallable; + } + + @Override + public UnaryCallable renewLeaseCallable() { + return renewLeaseCallable; + } + + @Override + public UnaryCallable cancelLeaseCallable() { + return cancelLeaseCallable; + } + + @Override + public UnaryCallable runTaskCallable() { + return runTaskCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksClient.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksClient.java index 24430428..32fdf62d 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksClient.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksClient.java @@ -106,6 +106,20 @@ * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings); * } * + *

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.
+ * CloudTasksSettings cloudTasksSettings =
+ *     CloudTasksSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudTasksSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudTasksClient cloudTasksClient = CloudTasksClient.create(cloudTasksSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -131,7 +145,6 @@ public static final CloudTasksClient create(CloudTasksSettings settings) throws * Constructs an instance of CloudTasksClient, using the given stub for making calls. This is for * advanced usage - prefer using create(CloudTasksSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final CloudTasksClient create(CloudTasksStub stub) { return new CloudTasksClient(stub); } @@ -145,7 +158,6 @@ protected CloudTasksClient(CloudTasksSettings settings) throws IOException { this.stub = ((CloudTasksStubSettings) settings.getStubSettings()).createStub(); } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") protected CloudTasksClient(CloudTasksStub stub) { this.settings = null; this.stub = stub; @@ -155,7 +167,6 @@ public final CloudTasksSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub getStub() { return stub; } @@ -304,7 +315,7 @@ public final UnaryCallable listQueue * .build(); * while (true) { * ListQueuesResponse response = cloudTasksClient.listQueuesCallable().call(request); - * for (Queue element : response.getResponsesList()) { + * for (Queue element : response.getQueuesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); @@ -1795,7 +1806,7 @@ public final UnaryCallable listTasksPa * .build(); * while (true) { * ListTasksResponse response = cloudTasksClient.listTasksCallable().call(request); - * for (Task element : response.getResponsesList()) { + * for (Task element : response.getTasksList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksSettings.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksSettings.java index 4b670b0a..027a308a 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksSettings.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/CloudTasksSettings.java @@ -24,6 +24,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; @@ -185,11 +186,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudTasksStubSettings.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 CloudTasksStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudTasksStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudTasksStubSettings.defaultTransportChannelProvider(); } @@ -199,11 +207,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudTasksStubSettings.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); @@ -241,6 +255,11 @@ private static Builder createDefault() { return new Builder(CloudTasksStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudTasksStubSettings.newHttpJsonBuilder()); + } + public CloudTasksStubSettings.Builder getStubSettingsBuilder() { return ((CloudTasksStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/CloudTasksStubSettings.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/CloudTasksStubSettings.java index d158d0c5..f932d379 100644 --- a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/CloudTasksStubSettings.java +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/CloudTasksStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -322,13 +325,17 @@ public UnaryCallSettings runTaskSettings() { return runTaskSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudTasksStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudTasksStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudTasksStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -361,18 +368,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(CloudTasksStubSettings.class)) @@ -380,11 +394,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(CloudTasksStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudTasksStubSettings.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); @@ -581,6 +614,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 .listQueuesSettings() diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksCallableFactory.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksCallableFactory.java new file mode 100644 index 00000000..954545e4 --- /dev/null +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2beta3.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 CloudTasks service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudTasksCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksStub.java b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksStub.java new file mode 100644 index 00000000..9b9fdbd6 --- /dev/null +++ b/google-cloud-tasks/src/main/java/com/google/cloud/tasks/v2beta3/stub/HttpJsonCloudTasksStub.java @@ -0,0 +1,984 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2beta3.stub; + +import static com.google.cloud.tasks.v2beta3.CloudTasksClient.ListQueuesPagedResponse; +import static com.google.cloud.tasks.v2beta3.CloudTasksClient.ListTasksPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.tasks.v2beta3.CreateQueueRequest; +import com.google.cloud.tasks.v2beta3.CreateTaskRequest; +import com.google.cloud.tasks.v2beta3.DeleteQueueRequest; +import com.google.cloud.tasks.v2beta3.DeleteTaskRequest; +import com.google.cloud.tasks.v2beta3.GetQueueRequest; +import com.google.cloud.tasks.v2beta3.GetTaskRequest; +import com.google.cloud.tasks.v2beta3.ListQueuesRequest; +import com.google.cloud.tasks.v2beta3.ListQueuesResponse; +import com.google.cloud.tasks.v2beta3.ListTasksRequest; +import com.google.cloud.tasks.v2beta3.ListTasksResponse; +import com.google.cloud.tasks.v2beta3.PauseQueueRequest; +import com.google.cloud.tasks.v2beta3.PurgeQueueRequest; +import com.google.cloud.tasks.v2beta3.Queue; +import com.google.cloud.tasks.v2beta3.ResumeQueueRequest; +import com.google.cloud.tasks.v2beta3.RunTaskRequest; +import com.google.cloud.tasks.v2beta3.Task; +import com.google.cloud.tasks.v2beta3.UpdateQueueRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.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 CloudTasks service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCloudTasksStub extends CloudTasksStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listQueuesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/ListQueues") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{parent=projects/*/locations/*}/queues", + 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()); + serializer.putQueryParam(fields, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListQueuesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/GetQueue") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*}", + 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, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/CreateQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{parent=projects/*/locations/*}/queues", + 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("queue", request.getQueue())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/UpdateQueue") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{queue.name=projects/*/locations/*/queues/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "queue.name", request.getQueue().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> ProtoRestSerializer.create().toBody("queue", request.getQueue())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/DeleteQueue") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor purgeQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/PurgeQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*}:purge", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor pauseQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/PauseQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*}:pause", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor resumeQueueMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/ResumeQueue") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*}:resume", + 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(Queue.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/GetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{resource=projects/*/locations/*/queues/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{resource=projects/*/locations/*/queues/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{resource=projects/*/locations/*/queues/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listTasksMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/ListTasks") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{parent=projects/*/locations/*/queues/*}/tasks", + 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, "responseView", request.getResponseView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListTasksResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/GetTask") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}", + 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, "responseView", request.getResponseView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/CreateTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{parent=projects/*/locations/*/queues/*}/tasks", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/DeleteTask") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor runTaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.tasks.v2beta3.CloudTasks/RunTask") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2beta3/{name=projects/*/locations/*/queues/*/tasks/*}:run", + 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(Task.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listQueuesCallable; + private final UnaryCallable listQueuesPagedCallable; + private final UnaryCallable getQueueCallable; + private final UnaryCallable createQueueCallable; + private final UnaryCallable updateQueueCallable; + private final UnaryCallable deleteQueueCallable; + private final UnaryCallable purgeQueueCallable; + private final UnaryCallable pauseQueueCallable; + private final UnaryCallable resumeQueueCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + private final UnaryCallable listTasksCallable; + private final UnaryCallable listTasksPagedCallable; + private final UnaryCallable getTaskCallable; + private final UnaryCallable createTaskCallable; + private final UnaryCallable deleteTaskCallable; + private final UnaryCallable runTaskCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudTasksStub create(CloudTasksStubSettings settings) + throws IOException { + return new HttpJsonCloudTasksStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudTasksStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudTasksStub( + CloudTasksStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudTasksStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudTasksStub( + CloudTasksStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudTasksStub, 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 HttpJsonCloudTasksStub(CloudTasksStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudTasksCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudTasksStub, 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 HttpJsonCloudTasksStub( + CloudTasksStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listQueuesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listQueuesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings purgeQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(purgeQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings pauseQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(pauseQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings resumeQueueTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(resumeQueueMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listTasksTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listTasksMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings runTaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(runTaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listQueuesCallable = + callableFactory.createUnaryCallable( + listQueuesTransportSettings, settings.listQueuesSettings(), clientContext); + this.listQueuesPagedCallable = + callableFactory.createPagedCallable( + listQueuesTransportSettings, settings.listQueuesSettings(), clientContext); + this.getQueueCallable = + callableFactory.createUnaryCallable( + getQueueTransportSettings, settings.getQueueSettings(), clientContext); + this.createQueueCallable = + callableFactory.createUnaryCallable( + createQueueTransportSettings, settings.createQueueSettings(), clientContext); + this.updateQueueCallable = + callableFactory.createUnaryCallable( + updateQueueTransportSettings, settings.updateQueueSettings(), clientContext); + this.deleteQueueCallable = + callableFactory.createUnaryCallable( + deleteQueueTransportSettings, settings.deleteQueueSettings(), clientContext); + this.purgeQueueCallable = + callableFactory.createUnaryCallable( + purgeQueueTransportSettings, settings.purgeQueueSettings(), clientContext); + this.pauseQueueCallable = + callableFactory.createUnaryCallable( + pauseQueueTransportSettings, settings.pauseQueueSettings(), clientContext); + this.resumeQueueCallable = + callableFactory.createUnaryCallable( + resumeQueueTransportSettings, settings.resumeQueueSettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + this.listTasksCallable = + callableFactory.createUnaryCallable( + listTasksTransportSettings, settings.listTasksSettings(), clientContext); + this.listTasksPagedCallable = + callableFactory.createPagedCallable( + listTasksTransportSettings, settings.listTasksSettings(), clientContext); + this.getTaskCallable = + callableFactory.createUnaryCallable( + getTaskTransportSettings, settings.getTaskSettings(), clientContext); + this.createTaskCallable = + callableFactory.createUnaryCallable( + createTaskTransportSettings, settings.createTaskSettings(), clientContext); + this.deleteTaskCallable = + callableFactory.createUnaryCallable( + deleteTaskTransportSettings, settings.deleteTaskSettings(), clientContext); + this.runTaskCallable = + callableFactory.createUnaryCallable( + runTaskTransportSettings, settings.runTaskSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listQueuesMethodDescriptor); + methodDescriptors.add(getQueueMethodDescriptor); + methodDescriptors.add(createQueueMethodDescriptor); + methodDescriptors.add(updateQueueMethodDescriptor); + methodDescriptors.add(deleteQueueMethodDescriptor); + methodDescriptors.add(purgeQueueMethodDescriptor); + methodDescriptors.add(pauseQueueMethodDescriptor); + methodDescriptors.add(resumeQueueMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + methodDescriptors.add(listTasksMethodDescriptor); + methodDescriptors.add(getTaskMethodDescriptor); + methodDescriptors.add(createTaskMethodDescriptor); + methodDescriptors.add(deleteTaskMethodDescriptor); + methodDescriptors.add(runTaskMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listQueuesCallable() { + return listQueuesCallable; + } + + @Override + public UnaryCallable listQueuesPagedCallable() { + return listQueuesPagedCallable; + } + + @Override + public UnaryCallable getQueueCallable() { + return getQueueCallable; + } + + @Override + public UnaryCallable createQueueCallable() { + return createQueueCallable; + } + + @Override + public UnaryCallable updateQueueCallable() { + return updateQueueCallable; + } + + @Override + public UnaryCallable deleteQueueCallable() { + return deleteQueueCallable; + } + + @Override + public UnaryCallable purgeQueueCallable() { + return purgeQueueCallable; + } + + @Override + public UnaryCallable pauseQueueCallable() { + return pauseQueueCallable; + } + + @Override + public UnaryCallable resumeQueueCallable() { + return resumeQueueCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public UnaryCallable listTasksCallable() { + return listTasksCallable; + } + + @Override + public UnaryCallable listTasksPagedCallable() { + return listTasksPagedCallable; + } + + @Override + public UnaryCallable getTaskCallable() { + return getTaskCallable; + } + + @Override + public UnaryCallable createTaskCallable() { + return createTaskCallable; + } + + @Override + public UnaryCallable deleteTaskCallable() { + return deleteTaskCallable; + } + + @Override + public UnaryCallable runTaskCallable() { + return runTaskCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2/CloudTasksClientHttpJsonTest.java b/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2/CloudTasksClientHttpJsonTest.java new file mode 100644 index 00000000..d9613017 --- /dev/null +++ b/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2/CloudTasksClientHttpJsonTest.java @@ -0,0 +1,1602 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2; + +import static com.google.cloud.tasks.v2.CloudTasksClient.ListQueuesPagedResponse; +import static com.google.cloud.tasks.v2.CloudTasksClient.ListTasksPagedResponse; + +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.resourcenames.ResourceName; +import com.google.cloud.tasks.v2.stub.HttpJsonCloudTasksStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.Policy; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudTasksClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudTasksClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudTasksStub.getMethodDescriptors(), CloudTasksSettings.getDefaultEndpoint()); + CloudTasksSettings settings = + CloudTasksSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudTasksSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudTasksClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listQueuesTest() throws Exception { + Queue responsesElement = Queue.newBuilder().build(); + ListQueuesResponse expectedResponse = + ListQueuesResponse.newBuilder() + .setNextPageToken("") + .addAllQueues(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListQueuesPagedResponse pagedListResponse = client.listQueues(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getQueuesList().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 listQueuesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listQueues(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listQueuesTest2() throws Exception { + Queue responsesElement = Queue.newBuilder().build(); + ListQueuesResponse expectedResponse = + ListQueuesResponse.newBuilder() + .setNextPageToken("") + .addAllQueues(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListQueuesPagedResponse pagedListResponse = client.listQueues(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getQueuesList().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 listQueuesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listQueues(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.getQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.getQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.getQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.getQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Queue queue = Queue.newBuilder().build(); + + Queue actualResponse = client.createQueue(parent, queue); + 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 createQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Queue queue = Queue.newBuilder().build(); + client.createQueue(parent, queue); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + Queue queue = Queue.newBuilder().build(); + + Queue actualResponse = client.createQueue(parent, queue); + 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 createQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Queue queue = Queue.newBuilder().build(); + client.createQueue(parent, queue); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Queue queue = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Queue actualResponse = client.updateQueue(queue, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Queue queue = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateQueue(queue, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteQueueTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + client.deleteQueue(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.deleteQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteQueueTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + client.deleteQueue(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.deleteQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.purgeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void purgeQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.purgeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.purgeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void purgeQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.purgeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.pauseQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pauseQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.pauseQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.pauseQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pauseQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.pauseQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.resumeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void resumeQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.resumeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setAppEngineRoutingOverride(AppEngineRouting.newBuilder().build()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.resumeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void resumeQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.resumeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Policy actualResponse = client.getIamPolicy(resource); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + + Policy actualResponse = client.getIamPolicy(resource); + 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 getIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + 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 setIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest2() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + 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 testIamPermissionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTasksTest() throws Exception { + Task responsesElement = Task.newBuilder().build(); + ListTasksResponse expectedResponse = + ListTasksResponse.newBuilder() + .setNextPageToken("") + .addAllTasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + ListTasksPagedResponse pagedListResponse = client.listTasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTasksList().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 listTasksExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.listTasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTasksTest2() throws Exception { + Task responsesElement = Task.newBuilder().build(); + ListTasksResponse expectedResponse = + ListTasksResponse.newBuilder() + .setNextPageToken("") + .addAllTasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + + ListTasksPagedResponse pagedListResponse = client.listTasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTasksList().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 listTasksExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + client.listTasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + Task actualResponse = client.getTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.getTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + Task actualResponse = client.getTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.getTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Task task = Task.newBuilder().build(); + + Task actualResponse = client.createTask(parent, task); + 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 createTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Task task = Task.newBuilder().build(); + client.createTask(parent, task); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Task task = Task.newBuilder().build(); + + Task actualResponse = client.createTask(parent, task); + 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 createTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Task task = Task.newBuilder().build(); + client.createTask(parent, task); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTaskTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + client.deleteTask(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.deleteTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTaskTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + client.deleteTask(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.deleteTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + Task actualResponse = client.runTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.runTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + Task actualResponse = client.runTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.runTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta2/CloudTasksClientHttpJsonTest.java b/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta2/CloudTasksClientHttpJsonTest.java new file mode 100644 index 00000000..e7def613 --- /dev/null +++ b/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta2/CloudTasksClientHttpJsonTest.java @@ -0,0 +1,1966 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2beta2; + +import static com.google.cloud.tasks.v2beta2.CloudTasksClient.ListQueuesPagedResponse; +import static com.google.cloud.tasks.v2beta2.CloudTasksClient.ListTasksPagedResponse; + +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.resourcenames.ResourceName; +import com.google.cloud.tasks.v2beta2.stub.HttpJsonCloudTasksStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.Policy; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudTasksClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudTasksClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudTasksStub.getMethodDescriptors(), CloudTasksSettings.getDefaultEndpoint()); + CloudTasksSettings settings = + CloudTasksSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudTasksSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudTasksClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listQueuesTest() throws Exception { + Queue responsesElement = Queue.newBuilder().build(); + ListQueuesResponse expectedResponse = + ListQueuesResponse.newBuilder() + .setNextPageToken("") + .addAllQueues(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListQueuesPagedResponse pagedListResponse = client.listQueues(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getQueuesList().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 listQueuesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listQueues(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listQueuesTest2() throws Exception { + Queue responsesElement = Queue.newBuilder().build(); + ListQueuesResponse expectedResponse = + ListQueuesResponse.newBuilder() + .setNextPageToken("") + .addAllQueues(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListQueuesPagedResponse pagedListResponse = client.listQueues(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getQueuesList().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 listQueuesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listQueues(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.getQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.getQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.getQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.getQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Queue queue = Queue.newBuilder().build(); + + Queue actualResponse = client.createQueue(parent, queue); + 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 createQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Queue queue = Queue.newBuilder().build(); + client.createQueue(parent, queue); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + Queue queue = Queue.newBuilder().build(); + + Queue actualResponse = client.createQueue(parent, queue); + 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 createQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Queue queue = Queue.newBuilder().build(); + client.createQueue(parent, queue); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Queue queue = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Queue actualResponse = client.updateQueue(queue, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Queue queue = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateQueue(queue, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteQueueTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + client.deleteQueue(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.deleteQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteQueueTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + client.deleteQueue(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.deleteQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.purgeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void purgeQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.purgeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.purgeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void purgeQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.purgeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.pauseQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pauseQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.pauseQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.pauseQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pauseQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.pauseQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.resumeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void resumeQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.resumeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.resumeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void resumeQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.resumeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Policy actualResponse = client.getIamPolicy(resource); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + + Policy actualResponse = client.getIamPolicy(resource); + 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 getIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + 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 setIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest2() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + 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 testIamPermissionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTasksTest() throws Exception { + Task responsesElement = Task.newBuilder().build(); + ListTasksResponse expectedResponse = + ListTasksResponse.newBuilder() + .setNextPageToken("") + .addAllTasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + ListTasksPagedResponse pagedListResponse = client.listTasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTasksList().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 listTasksExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.listTasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTasksTest2() throws Exception { + Task responsesElement = Task.newBuilder().build(); + ListTasksResponse expectedResponse = + ListTasksResponse.newBuilder() + .setNextPageToken("") + .addAllTasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + + ListTasksPagedResponse pagedListResponse = client.listTasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTasksList().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 listTasksExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + client.listTasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + Task actualResponse = client.getTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.getTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + Task actualResponse = client.getTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.getTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Task task = Task.newBuilder().build(); + + Task actualResponse = client.createTask(parent, task); + 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 createTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Task task = Task.newBuilder().build(); + client.createTask(parent, task); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Task task = Task.newBuilder().build(); + + Task actualResponse = client.createTask(parent, task); + 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 createTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Task task = Task.newBuilder().build(); + client.createTask(parent, task); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTaskTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + client.deleteTask(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.deleteTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTaskTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + client.deleteTask(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.deleteTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void leaseTasksTest() throws Exception { + LeaseTasksResponse expectedResponse = + LeaseTasksResponse.newBuilder().addAllTasks(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Duration leaseDuration = Duration.newBuilder().build(); + + LeaseTasksResponse actualResponse = client.leaseTasks(parent, leaseDuration); + 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 leaseTasksExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Duration leaseDuration = Duration.newBuilder().build(); + client.leaseTasks(parent, leaseDuration); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void leaseTasksTest2() throws Exception { + LeaseTasksResponse expectedResponse = + LeaseTasksResponse.newBuilder().addAllTasks(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Duration leaseDuration = Duration.newBuilder().build(); + + LeaseTasksResponse actualResponse = client.leaseTasks(parent, leaseDuration); + 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 leaseTasksExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Duration leaseDuration = Duration.newBuilder().build(); + client.leaseTasks(parent, leaseDuration); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void acknowledgeTaskTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + client.acknowledgeTask(name, scheduleTime); + + 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 acknowledgeTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.acknowledgeTask(name, scheduleTime); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void acknowledgeTaskTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + client.acknowledgeTask(name, scheduleTime); + + 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 acknowledgeTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.acknowledgeTask(name, scheduleTime); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void renewLeaseTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Duration leaseDuration = Duration.newBuilder().build(); + + Task actualResponse = client.renewLease(name, scheduleTime, leaseDuration); + 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 renewLeaseExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Duration leaseDuration = Duration.newBuilder().build(); + client.renewLease(name, scheduleTime, leaseDuration); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void renewLeaseTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Duration leaseDuration = Duration.newBuilder().build(); + + Task actualResponse = client.renewLease(name, scheduleTime, leaseDuration); + 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 renewLeaseExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + Timestamp scheduleTime = Timestamp.newBuilder().build(); + Duration leaseDuration = Duration.newBuilder().build(); + client.renewLease(name, scheduleTime, leaseDuration); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void cancelLeaseTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + Task actualResponse = client.cancelLease(name, scheduleTime); + 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 cancelLeaseExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.cancelLease(name, scheduleTime); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void cancelLeaseTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + Timestamp scheduleTime = Timestamp.newBuilder().build(); + + Task actualResponse = client.cancelLease(name, scheduleTime); + 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 cancelLeaseExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + Timestamp scheduleTime = Timestamp.newBuilder().build(); + client.cancelLease(name, scheduleTime); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + Task actualResponse = client.runTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.runTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setStatus(TaskStatus.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + Task actualResponse = client.runTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.runTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta3/CloudTasksClientHttpJsonTest.java b/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta3/CloudTasksClientHttpJsonTest.java new file mode 100644 index 00000000..00cd0812 --- /dev/null +++ b/google-cloud-tasks/src/test/java/com/google/cloud/tasks/v2beta3/CloudTasksClientHttpJsonTest.java @@ -0,0 +1,1628 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.tasks.v2beta3; + +import static com.google.cloud.tasks.v2beta3.CloudTasksClient.ListQueuesPagedResponse; +import static com.google.cloud.tasks.v2beta3.CloudTasksClient.ListTasksPagedResponse; + +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.resourcenames.ResourceName; +import com.google.cloud.tasks.v2beta3.stub.HttpJsonCloudTasksStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.Policy; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudTasksClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudTasksClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudTasksStub.getMethodDescriptors(), CloudTasksSettings.getDefaultEndpoint()); + CloudTasksSettings settings = + CloudTasksSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudTasksSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudTasksClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listQueuesTest() throws Exception { + Queue responsesElement = Queue.newBuilder().build(); + ListQueuesResponse expectedResponse = + ListQueuesResponse.newBuilder() + .setNextPageToken("") + .addAllQueues(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListQueuesPagedResponse pagedListResponse = client.listQueues(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getQueuesList().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 listQueuesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listQueues(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listQueuesTest2() throws Exception { + Queue responsesElement = Queue.newBuilder().build(); + ListQueuesResponse expectedResponse = + ListQueuesResponse.newBuilder() + .setNextPageToken("") + .addAllQueues(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListQueuesPagedResponse pagedListResponse = client.listQueues(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getQueuesList().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 listQueuesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listQueues(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.getQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.getQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.getQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.getQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Queue queue = Queue.newBuilder().build(); + + Queue actualResponse = client.createQueue(parent, queue); + 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 createQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Queue queue = Queue.newBuilder().build(); + client.createQueue(parent, queue); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + Queue queue = Queue.newBuilder().build(); + + Queue actualResponse = client.createQueue(parent, queue); + 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 createQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Queue queue = Queue.newBuilder().build(); + client.createQueue(parent, queue); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Queue queue = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + Queue actualResponse = client.updateQueue(queue, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Queue queue = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateQueue(queue, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteQueueTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + client.deleteQueue(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.deleteQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteQueueTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + client.deleteQueue(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.deleteQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.purgeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void purgeQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.purgeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.purgeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void purgeQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.purgeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.pauseQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pauseQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.pauseQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void pauseQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.pauseQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void pauseQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.pauseQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeQueueTest() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Queue actualResponse = client.resumeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void resumeQueueExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.resumeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void resumeQueueTest2() throws Exception { + Queue expectedResponse = + Queue.newBuilder() + .setName(QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]").toString()) + .setRateLimits(RateLimits.newBuilder().build()) + .setRetryConfig(RetryConfig.newBuilder().build()) + .setPurgeTime(Timestamp.newBuilder().build()) + .setTaskTtl(Duration.newBuilder().build()) + .setTombstoneTtl(Duration.newBuilder().build()) + .setStackdriverLoggingConfig(StackdriverLoggingConfig.newBuilder().build()) + .setStats(QueueStats.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + + Queue actualResponse = client.resumeQueue(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void resumeQueueExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3918/locations/location-3918/queues/queue-3918"; + client.resumeQueue(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + Policy actualResponse = client.getIamPolicy(resource); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + + Policy actualResponse = client.getIamPolicy(resource); + 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 getIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + 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 setIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest2() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + 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 testIamPermissionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "projects/project-1711/locations/location-1711/queues/queue-1711"; + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTasksTest() throws Exception { + Task responsesElement = Task.newBuilder().build(); + ListTasksResponse expectedResponse = + ListTasksResponse.newBuilder() + .setNextPageToken("") + .addAllTasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + + ListTasksPagedResponse pagedListResponse = client.listTasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTasksList().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 listTasksExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + client.listTasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTasksTest2() throws Exception { + Task responsesElement = Task.newBuilder().build(); + ListTasksResponse expectedResponse = + ListTasksResponse.newBuilder() + .setNextPageToken("") + .addAllTasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + + ListTasksPagedResponse pagedListResponse = client.listTasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getTasksList().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 listTasksExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + client.listTasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + Task actualResponse = client.getTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.getTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + Task actualResponse = client.getTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.getTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Task task = Task.newBuilder().build(); + + Task actualResponse = client.createTask(parent, task); + 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 createTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); + Task task = Task.newBuilder().build(); + client.createTask(parent, task); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Task task = Task.newBuilder().build(); + + Task actualResponse = client.createTask(parent, task); + 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 createTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-7117/locations/location-7117/queues/queue-7117"; + Task task = Task.newBuilder().build(); + client.createTask(parent, task); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTaskTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + client.deleteTask(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.deleteTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTaskTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + client.deleteTask(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.deleteTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runTaskTest() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + + Task actualResponse = client.runTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runTaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]"); + client.runTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runTaskTest2() throws Exception { + Task expectedResponse = + Task.newBuilder() + .setName(TaskName.of("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]").toString()) + .setScheduleTime(Timestamp.newBuilder().build()) + .setCreateTime(Timestamp.newBuilder().build()) + .setDispatchDeadline(Duration.newBuilder().build()) + .setDispatchCount(-1217252086) + .setResponseCount(424727441) + .setFirstAttempt(Attempt.newBuilder().build()) + .setLastAttempt(Attempt.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + + Task actualResponse = client.runTask(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runTaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3612/locations/location-3612/queues/queue-3612/tasks/task-3612"; + client.runTask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +}