From b3507db7d0e0063fb6e372356629aceb7c6ee1ed Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 23 Jun 2022 13:46:16 -0400 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#131) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * deps: adding gax-httpjson Co-authored-by: Owl Bot Co-authored-by: Tomo Suzuki --- .../google-cloud-bigquerymigration/pom.xml | 16 + .../migration/v2/MigrationServiceClient.java | 15 + .../v2/MigrationServiceSettings.java | 23 +- ...tpJsonMigrationServiceCallableFactory.java | 105 +++ .../v2/stub/HttpJsonMigrationServiceStub.java | 577 +++++++++++++ .../v2/stub/MigrationServiceStubSettings.java | 53 +- .../v2alpha/MigrationServiceClient.java | 15 + .../v2alpha/MigrationServiceSettings.java | 23 +- ...tpJsonMigrationServiceCallableFactory.java | 105 +++ .../stub/HttpJsonMigrationServiceStub.java | 577 +++++++++++++ .../stub/MigrationServiceStubSettings.java | 53 +- .../MigrationServiceClientHttpJsonTest.java | 756 ++++++++++++++++++ .../MigrationServiceClientHttpJsonTest.java | 756 ++++++++++++++++++ 13 files changed, 3064 insertions(+), 10 deletions(-) create mode 100644 java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceCallableFactory.java create mode 100644 java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceStub.java create mode 100644 java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceCallableFactory.java create mode 100644 java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceStub.java create mode 100644 java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClientHttpJsonTest.java create mode 100644 java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClientHttpJsonTest.java diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/pom.xml b/java-bigquerymigration/google-cloud-bigquerymigration/pom.xml index a949b5e49772..8a0f3db148e3 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/pom.xml +++ b/java-bigquerymigration/google-cloud-bigquerymigration/pom.xml @@ -62,6 +62,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -86,12 +90,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClient.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClient.java index a932c7bc87c8..5ee019f4848b 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClient.java +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClient.java @@ -102,6 +102,21 @@ * MigrationServiceClient.create(migrationServiceSettings); * } * + *

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.
+ * MigrationServiceSettings migrationServiceSettings =
+ *     MigrationServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             MigrationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * MigrationServiceClient migrationServiceClient =
+ *     MigrationServiceClient.create(migrationServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceSettings.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceSettings.java index c890fa24b095..d47dede752e8 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceSettings.java +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/MigrationServiceSettings.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; @@ -146,11 +147,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return MigrationServiceStubSettings.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 MigrationServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return MigrationServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return MigrationServiceStubSettings.defaultTransportChannelProvider(); } @@ -160,11 +168,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return MigrationServiceStubSettings.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); @@ -202,6 +216,11 @@ private static Builder createDefault() { return new Builder(MigrationServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(MigrationServiceStubSettings.newHttpJsonBuilder()); + } + public MigrationServiceStubSettings.Builder getStubSettingsBuilder() { return ((MigrationServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceCallableFactory.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceCallableFactory.java new file mode 100644 index 000000000000..52aa4c3c1472 --- /dev/null +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceCallableFactory.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.bigquery.migration.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 MigrationService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonMigrationServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceStub.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceStub.java new file mode 100644 index 000000000000..80c2948099d0 --- /dev/null +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/HttpJsonMigrationServiceStub.java @@ -0,0 +1,577 @@ +/* + * 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.bigquery.migration.v2.stub; + +import static com.google.cloud.bigquery.migration.v2.MigrationServiceClient.ListMigrationSubtasksPagedResponse; +import static com.google.cloud.bigquery.migration.v2.MigrationServiceClient.ListMigrationWorkflowsPagedResponse; + +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.bigquery.migration.v2.CreateMigrationWorkflowRequest; +import com.google.cloud.bigquery.migration.v2.DeleteMigrationWorkflowRequest; +import com.google.cloud.bigquery.migration.v2.GetMigrationSubtaskRequest; +import com.google.cloud.bigquery.migration.v2.GetMigrationWorkflowRequest; +import com.google.cloud.bigquery.migration.v2.ListMigrationSubtasksRequest; +import com.google.cloud.bigquery.migration.v2.ListMigrationSubtasksResponse; +import com.google.cloud.bigquery.migration.v2.ListMigrationWorkflowsRequest; +import com.google.cloud.bigquery.migration.v2.ListMigrationWorkflowsResponse; +import com.google.cloud.bigquery.migration.v2.MigrationSubtask; +import com.google.cloud.bigquery.migration.v2.MigrationWorkflow; +import com.google.cloud.bigquery.migration.v2.StartMigrationWorkflowRequest; +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 MigrationService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonMigrationServiceStub extends MigrationServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + createMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/CreateMigrationWorkflow") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*}/workflows", + 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("migrationWorkflow", request.getMigrationWorkflow())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(MigrationWorkflow.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/GetMigrationWorkflow") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/workflows/*}", + 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(MigrationWorkflow.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListMigrationWorkflowsRequest, ListMigrationWorkflowsResponse> + listMigrationWorkflowsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/ListMigrationWorkflows") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*}/workflows", + 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, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListMigrationWorkflowsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/DeleteMigrationWorkflow") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/workflows/*}", + 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 + startMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/StartMigrationWorkflow") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/workflows/*}:start", + 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 + getMigrationSubtaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/GetMigrationSubtask") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/locations/*/workflows/*/subtasks/*}", + 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(MigrationSubtask.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListMigrationSubtasksRequest, ListMigrationSubtasksResponse> + listMigrationSubtasksMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2.MigrationService/ListMigrationSubtasks") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*/locations/*/workflows/*}/subtasks", + 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(ListMigrationSubtasksResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + createMigrationWorkflowCallable; + private final UnaryCallable + getMigrationWorkflowCallable; + private final UnaryCallable + listMigrationWorkflowsCallable; + private final UnaryCallable + listMigrationWorkflowsPagedCallable; + private final UnaryCallable + deleteMigrationWorkflowCallable; + private final UnaryCallable startMigrationWorkflowCallable; + private final UnaryCallable + getMigrationSubtaskCallable; + private final UnaryCallable + listMigrationSubtasksCallable; + private final UnaryCallable + listMigrationSubtasksPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonMigrationServiceStub create(MigrationServiceStubSettings settings) + throws IOException { + return new HttpJsonMigrationServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonMigrationServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonMigrationServiceStub( + MigrationServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonMigrationServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonMigrationServiceStub( + MigrationServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonMigrationServiceStub, 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 HttpJsonMigrationServiceStub( + MigrationServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonMigrationServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonMigrationServiceStub, 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 HttpJsonMigrationServiceStub( + MigrationServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + createMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listMigrationWorkflowsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listMigrationWorkflowsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + startMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(startMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getMigrationSubtaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getMigrationSubtaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listMigrationSubtasksTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listMigrationSubtasksMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + createMigrationWorkflowTransportSettings, + settings.createMigrationWorkflowSettings(), + clientContext); + this.getMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + getMigrationWorkflowTransportSettings, + settings.getMigrationWorkflowSettings(), + clientContext); + this.listMigrationWorkflowsCallable = + callableFactory.createUnaryCallable( + listMigrationWorkflowsTransportSettings, + settings.listMigrationWorkflowsSettings(), + clientContext); + this.listMigrationWorkflowsPagedCallable = + callableFactory.createPagedCallable( + listMigrationWorkflowsTransportSettings, + settings.listMigrationWorkflowsSettings(), + clientContext); + this.deleteMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + deleteMigrationWorkflowTransportSettings, + settings.deleteMigrationWorkflowSettings(), + clientContext); + this.startMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + startMigrationWorkflowTransportSettings, + settings.startMigrationWorkflowSettings(), + clientContext); + this.getMigrationSubtaskCallable = + callableFactory.createUnaryCallable( + getMigrationSubtaskTransportSettings, + settings.getMigrationSubtaskSettings(), + clientContext); + this.listMigrationSubtasksCallable = + callableFactory.createUnaryCallable( + listMigrationSubtasksTransportSettings, + settings.listMigrationSubtasksSettings(), + clientContext); + this.listMigrationSubtasksPagedCallable = + callableFactory.createPagedCallable( + listMigrationSubtasksTransportSettings, + settings.listMigrationSubtasksSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createMigrationWorkflowMethodDescriptor); + methodDescriptors.add(getMigrationWorkflowMethodDescriptor); + methodDescriptors.add(listMigrationWorkflowsMethodDescriptor); + methodDescriptors.add(deleteMigrationWorkflowMethodDescriptor); + methodDescriptors.add(startMigrationWorkflowMethodDescriptor); + methodDescriptors.add(getMigrationSubtaskMethodDescriptor); + methodDescriptors.add(listMigrationSubtasksMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + createMigrationWorkflowCallable() { + return createMigrationWorkflowCallable; + } + + @Override + public UnaryCallable + getMigrationWorkflowCallable() { + return getMigrationWorkflowCallable; + } + + @Override + public UnaryCallable + listMigrationWorkflowsCallable() { + return listMigrationWorkflowsCallable; + } + + @Override + public UnaryCallable + listMigrationWorkflowsPagedCallable() { + return listMigrationWorkflowsPagedCallable; + } + + @Override + public UnaryCallable deleteMigrationWorkflowCallable() { + return deleteMigrationWorkflowCallable; + } + + @Override + public UnaryCallable startMigrationWorkflowCallable() { + return startMigrationWorkflowCallable; + } + + @Override + public UnaryCallable getMigrationSubtaskCallable() { + return getMigrationSubtaskCallable; + } + + @Override + public UnaryCallable + listMigrationSubtasksCallable() { + return listMigrationSubtasksCallable; + } + + @Override + public UnaryCallable + listMigrationSubtasksPagedCallable() { + return listMigrationSubtasksPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/MigrationServiceStubSettings.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/MigrationServiceStubSettings.java index 0d358b8a5289..f2973821128a 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/MigrationServiceStubSettings.java +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2/stub/MigrationServiceStubSettings.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; @@ -312,6 +315,11 @@ public MigrationServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcMigrationServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonMigrationServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -344,18 +352,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(MigrationServiceStubSettings.class)) @@ -363,11 +378,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(MigrationServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return MigrationServiceStubSettings.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); @@ -521,6 +555,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 .createMigrationWorkflowSettings() diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClient.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClient.java index 4ece8d26b6c9..cb49f5cc109f 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClient.java +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClient.java @@ -103,6 +103,21 @@ * MigrationServiceClient.create(migrationServiceSettings); * } * + *

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.
+ * MigrationServiceSettings migrationServiceSettings =
+ *     MigrationServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             MigrationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * MigrationServiceClient migrationServiceClient =
+ *     MigrationServiceClient.create(migrationServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceSettings.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceSettings.java index 7b737db5780b..f89c40adaba1 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceSettings.java +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceSettings.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; @@ -147,11 +148,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return MigrationServiceStubSettings.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 MigrationServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return MigrationServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return MigrationServiceStubSettings.defaultTransportChannelProvider(); } @@ -161,11 +169,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return MigrationServiceStubSettings.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); @@ -203,6 +217,11 @@ private static Builder createDefault() { return new Builder(MigrationServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(MigrationServiceStubSettings.newHttpJsonBuilder()); + } + public MigrationServiceStubSettings.Builder getStubSettingsBuilder() { return ((MigrationServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceCallableFactory.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceCallableFactory.java new file mode 100644 index 000000000000..4f39e0f13db2 --- /dev/null +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceCallableFactory.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.bigquery.migration.v2alpha.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 MigrationService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonMigrationServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceStub.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceStub.java new file mode 100644 index 000000000000..cd65aaae2b33 --- /dev/null +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/HttpJsonMigrationServiceStub.java @@ -0,0 +1,577 @@ +/* + * 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.bigquery.migration.v2alpha.stub; + +import static com.google.cloud.bigquery.migration.v2alpha.MigrationServiceClient.ListMigrationSubtasksPagedResponse; +import static com.google.cloud.bigquery.migration.v2alpha.MigrationServiceClient.ListMigrationWorkflowsPagedResponse; + +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.bigquery.migration.v2alpha.CreateMigrationWorkflowRequest; +import com.google.cloud.bigquery.migration.v2alpha.DeleteMigrationWorkflowRequest; +import com.google.cloud.bigquery.migration.v2alpha.GetMigrationSubtaskRequest; +import com.google.cloud.bigquery.migration.v2alpha.GetMigrationWorkflowRequest; +import com.google.cloud.bigquery.migration.v2alpha.ListMigrationSubtasksRequest; +import com.google.cloud.bigquery.migration.v2alpha.ListMigrationSubtasksResponse; +import com.google.cloud.bigquery.migration.v2alpha.ListMigrationWorkflowsRequest; +import com.google.cloud.bigquery.migration.v2alpha.ListMigrationWorkflowsResponse; +import com.google.cloud.bigquery.migration.v2alpha.MigrationSubtask; +import com.google.cloud.bigquery.migration.v2alpha.MigrationWorkflow; +import com.google.cloud.bigquery.migration.v2alpha.StartMigrationWorkflowRequest; +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 MigrationService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonMigrationServiceStub extends MigrationServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + createMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/CreateMigrationWorkflow") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{parent=projects/*/locations/*}/workflows", + 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("migrationWorkflow", request.getMigrationWorkflow())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(MigrationWorkflow.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/GetMigrationWorkflow") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{name=projects/*/locations/*/workflows/*}", + 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(MigrationWorkflow.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListMigrationWorkflowsRequest, ListMigrationWorkflowsResponse> + listMigrationWorkflowsMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/ListMigrationWorkflows") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{parent=projects/*/locations/*}/workflows", + 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, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListMigrationWorkflowsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/DeleteMigrationWorkflow") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{name=projects/*/locations/*/workflows/*}", + 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 + startMigrationWorkflowMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/StartMigrationWorkflow") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{name=projects/*/locations/*/workflows/*}:start", + 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 + getMigrationSubtaskMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/GetMigrationSubtask") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{name=projects/*/locations/*/workflows/*/subtasks/*}", + 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(MigrationSubtask.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListMigrationSubtasksRequest, ListMigrationSubtasksResponse> + listMigrationSubtasksMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.bigquery.migration.v2alpha.MigrationService/ListMigrationSubtasks") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2alpha/{parent=projects/*/locations/*/workflows/*}/subtasks", + 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(ListMigrationSubtasksResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + createMigrationWorkflowCallable; + private final UnaryCallable + getMigrationWorkflowCallable; + private final UnaryCallable + listMigrationWorkflowsCallable; + private final UnaryCallable + listMigrationWorkflowsPagedCallable; + private final UnaryCallable + deleteMigrationWorkflowCallable; + private final UnaryCallable startMigrationWorkflowCallable; + private final UnaryCallable + getMigrationSubtaskCallable; + private final UnaryCallable + listMigrationSubtasksCallable; + private final UnaryCallable + listMigrationSubtasksPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonMigrationServiceStub create(MigrationServiceStubSettings settings) + throws IOException { + return new HttpJsonMigrationServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonMigrationServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonMigrationServiceStub( + MigrationServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonMigrationServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonMigrationServiceStub( + MigrationServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonMigrationServiceStub, 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 HttpJsonMigrationServiceStub( + MigrationServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonMigrationServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonMigrationServiceStub, 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 HttpJsonMigrationServiceStub( + MigrationServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + createMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listMigrationWorkflowsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listMigrationWorkflowsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deleteMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + startMigrationWorkflowTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(startMigrationWorkflowMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getMigrationSubtaskTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getMigrationSubtaskMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listMigrationSubtasksTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listMigrationSubtasksMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + createMigrationWorkflowTransportSettings, + settings.createMigrationWorkflowSettings(), + clientContext); + this.getMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + getMigrationWorkflowTransportSettings, + settings.getMigrationWorkflowSettings(), + clientContext); + this.listMigrationWorkflowsCallable = + callableFactory.createUnaryCallable( + listMigrationWorkflowsTransportSettings, + settings.listMigrationWorkflowsSettings(), + clientContext); + this.listMigrationWorkflowsPagedCallable = + callableFactory.createPagedCallable( + listMigrationWorkflowsTransportSettings, + settings.listMigrationWorkflowsSettings(), + clientContext); + this.deleteMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + deleteMigrationWorkflowTransportSettings, + settings.deleteMigrationWorkflowSettings(), + clientContext); + this.startMigrationWorkflowCallable = + callableFactory.createUnaryCallable( + startMigrationWorkflowTransportSettings, + settings.startMigrationWorkflowSettings(), + clientContext); + this.getMigrationSubtaskCallable = + callableFactory.createUnaryCallable( + getMigrationSubtaskTransportSettings, + settings.getMigrationSubtaskSettings(), + clientContext); + this.listMigrationSubtasksCallable = + callableFactory.createUnaryCallable( + listMigrationSubtasksTransportSettings, + settings.listMigrationSubtasksSettings(), + clientContext); + this.listMigrationSubtasksPagedCallable = + callableFactory.createPagedCallable( + listMigrationSubtasksTransportSettings, + settings.listMigrationSubtasksSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createMigrationWorkflowMethodDescriptor); + methodDescriptors.add(getMigrationWorkflowMethodDescriptor); + methodDescriptors.add(listMigrationWorkflowsMethodDescriptor); + methodDescriptors.add(deleteMigrationWorkflowMethodDescriptor); + methodDescriptors.add(startMigrationWorkflowMethodDescriptor); + methodDescriptors.add(getMigrationSubtaskMethodDescriptor); + methodDescriptors.add(listMigrationSubtasksMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + createMigrationWorkflowCallable() { + return createMigrationWorkflowCallable; + } + + @Override + public UnaryCallable + getMigrationWorkflowCallable() { + return getMigrationWorkflowCallable; + } + + @Override + public UnaryCallable + listMigrationWorkflowsCallable() { + return listMigrationWorkflowsCallable; + } + + @Override + public UnaryCallable + listMigrationWorkflowsPagedCallable() { + return listMigrationWorkflowsPagedCallable; + } + + @Override + public UnaryCallable deleteMigrationWorkflowCallable() { + return deleteMigrationWorkflowCallable; + } + + @Override + public UnaryCallable startMigrationWorkflowCallable() { + return startMigrationWorkflowCallable; + } + + @Override + public UnaryCallable getMigrationSubtaskCallable() { + return getMigrationSubtaskCallable; + } + + @Override + public UnaryCallable + listMigrationSubtasksCallable() { + return listMigrationSubtasksCallable; + } + + @Override + public UnaryCallable + listMigrationSubtasksPagedCallable() { + return listMigrationSubtasksPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/MigrationServiceStubSettings.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/MigrationServiceStubSettings.java index a308732508c3..37c6cb9644ff 100644 --- a/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/MigrationServiceStubSettings.java +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/main/java/com/google/cloud/bigquery/migration/v2alpha/stub/MigrationServiceStubSettings.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; @@ -313,6 +316,11 @@ public MigrationServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcMigrationServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonMigrationServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -345,18 +353,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(MigrationServiceStubSettings.class)) @@ -364,11 +379,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(MigrationServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return MigrationServiceStubSettings.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); @@ -519,6 +553,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 .createMigrationWorkflowSettings() diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClientHttpJsonTest.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..d494d544b4b3 --- /dev/null +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2/MigrationServiceClientHttpJsonTest.java @@ -0,0 +1,756 @@ +/* + * 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.bigquery.migration.v2; + +import static com.google.cloud.bigquery.migration.v2.MigrationServiceClient.ListMigrationSubtasksPagedResponse; +import static com.google.cloud.bigquery.migration.v2.MigrationServiceClient.ListMigrationWorkflowsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.bigquery.migration.v2.stub.HttpJsonMigrationServiceStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.protobuf.Timestamp; +import com.google.rpc.ErrorInfo; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 MigrationServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static MigrationServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonMigrationServiceStub.getMethodDescriptors(), + MigrationServiceSettings.getDefaultEndpoint()); + MigrationServiceSettings settings = + MigrationServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + MigrationServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = MigrationServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createMigrationWorkflowTest() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + + MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); + 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 createMigrationWorkflowExceptionTest() 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]"); + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + client.createMigrationWorkflow(parent, migrationWorkflow); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createMigrationWorkflowTest2() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + + MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); + 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 createMigrationWorkflowExceptionTest2() 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"; + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + client.createMigrationWorkflow(parent, migrationWorkflow); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationWorkflowTest() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + MigrationWorkflow actualResponse = client.getMigrationWorkflow(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 getMigrationWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName name = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.getMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationWorkflowTest2() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + MigrationWorkflow actualResponse = client.getMigrationWorkflow(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 getMigrationWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.getMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationWorkflowsTest() throws Exception { + MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); + ListMigrationWorkflowsResponse expectedResponse = + ListMigrationWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().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 listMigrationWorkflowsExceptionTest() 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.listMigrationWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationWorkflowsTest2() throws Exception { + MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); + ListMigrationWorkflowsResponse expectedResponse = + ListMigrationWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().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 listMigrationWorkflowsExceptionTest2() 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.listMigrationWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteMigrationWorkflowTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + client.deleteMigrationWorkflow(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 deleteMigrationWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName name = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.deleteMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteMigrationWorkflowTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + client.deleteMigrationWorkflow(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 deleteMigrationWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.deleteMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void startMigrationWorkflowTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + client.startMigrationWorkflow(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 startMigrationWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName name = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.startMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void startMigrationWorkflowTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + client.startMigrationWorkflow(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 startMigrationWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.startMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationSubtaskTest() throws Exception { + MigrationSubtask expectedResponse = + MigrationSubtask.newBuilder() + .setName( + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") + .toString()) + .setTaskId("taskId-880873088") + .setType("type3575610") + .setProcessingError(ErrorInfo.newBuilder().build()) + .addAllResourceErrorDetails(new ArrayList()) + .setResourceErrorCount(-929997465) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .addAllMetrics(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + MigrationSubtaskName name = + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); + + MigrationSubtask actualResponse = client.getMigrationSubtask(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 getMigrationSubtaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationSubtaskName name = + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); + client.getMigrationSubtask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationSubtaskTest2() throws Exception { + MigrationSubtask expectedResponse = + MigrationSubtask.newBuilder() + .setName( + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") + .toString()) + .setTaskId("taskId-880873088") + .setType("type3575610") + .setProcessingError(ErrorInfo.newBuilder().build()) + .addAllResourceErrorDetails(new ArrayList()) + .setResourceErrorCount(-929997465) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .addAllMetrics(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-3070/locations/location-3070/workflows/workflow-3070/subtasks/subtask-3070"; + + MigrationSubtask actualResponse = client.getMigrationSubtask(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 getMigrationSubtaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3070/locations/location-3070/workflows/workflow-3070/subtasks/subtask-3070"; + client.getMigrationSubtask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationSubtasksTest() throws Exception { + MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); + ListMigrationSubtasksResponse expectedResponse = + ListMigrationSubtasksResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationSubtasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName parent = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationSubtasksList().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 listMigrationSubtasksExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName parent = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.listMigrationSubtasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationSubtasksTest2() throws Exception { + MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); + ListMigrationSubtasksResponse expectedResponse = + ListMigrationSubtasksResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationSubtasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9319/locations/location-9319/workflows/workflow-9319"; + + ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationSubtasksList().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 listMigrationSubtasksExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9319/locations/location-9319/workflows/workflow-9319"; + client.listMigrationSubtasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClientHttpJsonTest.java b/java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..82f432963d04 --- /dev/null +++ b/java-bigquerymigration/google-cloud-bigquerymigration/src/test/java/com/google/cloud/bigquery/migration/v2alpha/MigrationServiceClientHttpJsonTest.java @@ -0,0 +1,756 @@ +/* + * 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.bigquery.migration.v2alpha; + +import static com.google.cloud.bigquery.migration.v2alpha.MigrationServiceClient.ListMigrationSubtasksPagedResponse; +import static com.google.cloud.bigquery.migration.v2alpha.MigrationServiceClient.ListMigrationWorkflowsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.bigquery.migration.v2alpha.stub.HttpJsonMigrationServiceStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import com.google.protobuf.Timestamp; +import com.google.rpc.ErrorInfo; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 MigrationServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static MigrationServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonMigrationServiceStub.getMethodDescriptors(), + MigrationServiceSettings.getDefaultEndpoint()); + MigrationServiceSettings settings = + MigrationServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + MigrationServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = MigrationServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createMigrationWorkflowTest() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + + MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); + 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 createMigrationWorkflowExceptionTest() 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]"); + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + client.createMigrationWorkflow(parent, migrationWorkflow); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createMigrationWorkflowTest2() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + + MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); + 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 createMigrationWorkflowExceptionTest2() 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"; + MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); + client.createMigrationWorkflow(parent, migrationWorkflow); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationWorkflowTest() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + MigrationWorkflow actualResponse = client.getMigrationWorkflow(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 getMigrationWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName name = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.getMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationWorkflowTest2() throws Exception { + MigrationWorkflow expectedResponse = + MigrationWorkflow.newBuilder() + .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) + .setDisplayName("displayName1714148973") + .putAllTasks(new HashMap()) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + MigrationWorkflow actualResponse = client.getMigrationWorkflow(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 getMigrationWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.getMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationWorkflowsTest() throws Exception { + MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); + ListMigrationWorkflowsResponse expectedResponse = + ListMigrationWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().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 listMigrationWorkflowsExceptionTest() 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.listMigrationWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationWorkflowsTest2() throws Exception { + MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); + ListMigrationWorkflowsResponse expectedResponse = + ListMigrationWorkflowsResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationWorkflows(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().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 listMigrationWorkflowsExceptionTest2() 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.listMigrationWorkflows(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteMigrationWorkflowTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + client.deleteMigrationWorkflow(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 deleteMigrationWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName name = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.deleteMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteMigrationWorkflowTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + client.deleteMigrationWorkflow(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 deleteMigrationWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.deleteMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void startMigrationWorkflowTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + client.startMigrationWorkflow(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 startMigrationWorkflowExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName name = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.startMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void startMigrationWorkflowTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + + client.startMigrationWorkflow(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 startMigrationWorkflowExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; + client.startMigrationWorkflow(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationSubtaskTest() throws Exception { + MigrationSubtask expectedResponse = + MigrationSubtask.newBuilder() + .setName( + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") + .toString()) + .setTaskId("taskId-880873088") + .setType("type3575610") + .setProcessingError(ErrorInfo.newBuilder().build()) + .addAllResourceErrorDetails(new ArrayList()) + .setResourceErrorCount(-929997465) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .addAllMetrics(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + MigrationSubtaskName name = + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); + + MigrationSubtask actualResponse = client.getMigrationSubtask(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 getMigrationSubtaskExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationSubtaskName name = + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); + client.getMigrationSubtask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getMigrationSubtaskTest2() throws Exception { + MigrationSubtask expectedResponse = + MigrationSubtask.newBuilder() + .setName( + MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") + .toString()) + .setTaskId("taskId-880873088") + .setType("type3575610") + .setProcessingError(ErrorInfo.newBuilder().build()) + .addAllResourceErrorDetails(new ArrayList()) + .setResourceErrorCount(-929997465) + .setCreateTime(Timestamp.newBuilder().build()) + .setLastUpdateTime(Timestamp.newBuilder().build()) + .addAllMetrics(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-3070/locations/location-3070/workflows/workflow-3070/subtasks/subtask-3070"; + + MigrationSubtask actualResponse = client.getMigrationSubtask(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 getMigrationSubtaskExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-3070/locations/location-3070/workflows/workflow-3070/subtasks/subtask-3070"; + client.getMigrationSubtask(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationSubtasksTest() throws Exception { + MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); + ListMigrationSubtasksResponse expectedResponse = + ListMigrationSubtasksResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationSubtasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + MigrationWorkflowName parent = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + + ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationSubtasksList().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 listMigrationSubtasksExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + MigrationWorkflowName parent = + MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); + client.listMigrationSubtasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMigrationSubtasksTest2() throws Exception { + MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); + ListMigrationSubtasksResponse expectedResponse = + ListMigrationSubtasksResponse.newBuilder() + .setNextPageToken("") + .addAllMigrationSubtasks(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-9319/locations/location-9319/workflows/workflow-9319"; + + ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMigrationSubtasksList().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 listMigrationSubtasksExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-9319/locations/location-9319/workflows/workflow-9319"; + client.listMigrationSubtasks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +}