diff --git a/dependencies.properties b/dependencies.properties index fbdc353a59..7a8357ca63 100644 --- a/dependencies.properties +++ b/dependencies.properties @@ -7,7 +7,7 @@ # Target workspace name: com_google_api_codegen # Versions only, for dependencies which actual artifacts differ between Bazel and Gradle -version.com_google_protobuf=3.15.2 +version.com_google_protobuf=3.15.8 # Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8. version.google_java_format=1.7 version.com_google_api_common_java=1.9.3 diff --git a/repositories.bzl b/repositories.bzl index e246cef5cc..6d37762dfa 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -59,9 +59,18 @@ def gapic_generator_java_repositories(): _maybe( http_archive, name = "com_google_googleapis", - strip_prefix = "googleapis-2bea43cdc7a4443876380732980d83cd8d560582", + strip_prefix = "googleapis-f5ce261910c373fdd96bdaa47173f5604562876f", urls = [ - "https://github.com/googleapis/googleapis/archive/2bea43cdc7a4443876380732980d83cd8d560582.zip", + "https://github.com/googleapis/googleapis/archive/f5ce261910c373fdd96bdaa47173f5604562876f.zip", + ], + ) + + _maybe( + http_archive, + name = "com_google_googleapis_discovery", + strip_prefix = "googleapis-discovery-4f5d0604132e93e63330e65e2e6648c75012780c", + urls = [ + "https://github.com/googleapis/googleapis-discovery/archive/4f5d0604132e93e63330e65e2e6648c75012780c.zip", ], ) diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 23360e672b..db8a0bf839 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -29,6 +29,7 @@ INTEGRATION_TEST_LIBRARIES = [ "logging", # Java package remapping in gapic.yaml. "redis", # Has a gapic.yaml. "library", # No gRPC service config. + "compute", # REGAPIC test. ] # Keys must match the values in INTEGRATION_TEST_LIBRARIES above. @@ -41,6 +42,7 @@ API_GAPIC_TARGETS = { "logging": "@com_google_googleapis//google/logging/v2:logging_java_gapic", "redis": "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_gapic", "library": "@com_google_googleapis//google/example/library/v1:library_java_gapic", + "compute": "@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_java_gapic", } [integration_test( diff --git a/test/integration/goldens/compute/BUILD.bazel b/test/integration/goldens/compute/BUILD.bazel new file mode 100644 index 0000000000..2822013159 --- /dev/null +++ b/test/integration/goldens/compute/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "goldens_files", + srcs = glob( + ["**/*"], + exclude = [ + "BUILD.bazel", + ".*.sw*", + ], + ), +) diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesClient.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesClient.java new file mode 100644 index 0000000000..8323bbbbcd --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesClient.java @@ -0,0 +1,502 @@ +/* + * Copyright 2021 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.compute.v1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.compute.v1.stub.AddressesStub; +import com.google.cloud.compute.v1.stub.AddressesStubSettings; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: Services + * + *

The Addresses API. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * try (AddressesClient addressesClient = AddressesClient.create()) {
+ *   String project = "project-309310695";
+ *   AddressAggregatedList response = addressesClient.aggregatedList(project);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the AddressesClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of AddressesSettings to create(). + * For example: + * + *

To customize credentials: + * + *

{@code
+ * AddressesSettings addressesSettings =
+ *     AddressesSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * AddressesClient addressesClient = AddressesClient.create(addressesSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * AddressesSettings addressesSettings =
+ *     AddressesSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * AddressesClient addressesClient = AddressesClient.create(addressesSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@Generated("by gapic-generator-java") +public class AddressesClient implements BackgroundResource { + private final AddressesSettings settings; + private final AddressesStub stub; + + /** Constructs an instance of AddressesClient with default settings. */ + public static final AddressesClient create() throws IOException { + return create(AddressesSettings.newBuilder().build()); + } + + /** + * Constructs an instance of AddressesClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final AddressesClient create(AddressesSettings settings) throws IOException { + return new AddressesClient(settings); + } + + /** + * Constructs an instance of AddressesClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(AddressesSettings). + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final AddressesClient create(AddressesStub stub) { + return new AddressesClient(stub); + } + + /** + * Constructs an instance of AddressesClient, 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 AddressesClient(AddressesSettings settings) throws IOException { + this.settings = settings; + this.stub = ((AddressesStubSettings) settings.getStubSettings()).createStub(); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected AddressesClient(AddressesStub stub) { + this.settings = null; + this.stub = stub; + } + + public final AddressesSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public AddressesStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves an aggregated list of addresses. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   String project = "project-309310695";
+   *   AddressAggregatedList response = addressesClient.aggregatedList(project);
+   * }
+   * }
+ * + * @param project Project ID for this request. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AddressAggregatedList aggregatedList(String project) { + AggregatedListAddressesRequest request = + AggregatedListAddressesRequest.newBuilder().setProject(project).build(); + return aggregatedList(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves an aggregated list of addresses. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   AggregatedListAddressesRequest request =
+   *       AggregatedListAddressesRequest.newBuilder()
+   *           .setFilter("filter-1274492040")
+   *           .setIncludeAllScopes(true)
+   *           .setMaxResults(1128457243)
+   *           .setOrderBy("orderBy-1207110587")
+   *           .setPageToken("pageToken873572522")
+   *           .setProject("project-309310695")
+   *           .build();
+   *   AddressAggregatedList response = addressesClient.aggregatedList(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AddressAggregatedList aggregatedList(AggregatedListAddressesRequest request) { + return aggregatedListCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves an aggregated list of addresses. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   AggregatedListAddressesRequest request =
+   *       AggregatedListAddressesRequest.newBuilder()
+   *           .setFilter("filter-1274492040")
+   *           .setIncludeAllScopes(true)
+   *           .setMaxResults(1128457243)
+   *           .setOrderBy("orderBy-1207110587")
+   *           .setPageToken("pageToken873572522")
+   *           .setProject("project-309310695")
+   *           .build();
+   *   ApiFuture future =
+   *       addressesClient.aggregatedListCallable().futureCall(request);
+   *   // Do something.
+   *   AddressAggregatedList response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + aggregatedListCallable() { + return stub.aggregatedListCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes the specified address resource. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   String project = "project-309310695";
+   *   String region = "region-934795532";
+   *   String address = "address-1147692044";
+   *   Operation response = addressesClient.delete(project, region, address);
+   * }
+   * }
+ * + * @param project Project ID for this request. + * @param region Name of the region for this request. + * @param address Name of the address resource to delete. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Operation delete(String project, String region, String address) { + DeleteAddressRequest request = + DeleteAddressRequest.newBuilder() + .setProject(project) + .setRegion(region) + .setAddress(address) + .build(); + return delete(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes the specified address resource. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   DeleteAddressRequest request =
+   *       DeleteAddressRequest.newBuilder()
+   *           .setAddress("address-1147692044")
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .setRequestId("requestId693933066")
+   *           .build();
+   *   Operation response = addressesClient.delete(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Operation delete(DeleteAddressRequest request) { + return deleteCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes the specified address resource. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   DeleteAddressRequest request =
+   *       DeleteAddressRequest.newBuilder()
+   *           .setAddress("address-1147692044")
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .setRequestId("requestId693933066")
+   *           .build();
+   *   ApiFuture future = addressesClient.deleteCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable deleteCallable() { + return stub.deleteCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates an address resource in the specified project by using the data included in the request. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   String project = "project-309310695";
+   *   String region = "region-934795532";
+   *   Address addressResource = Address.newBuilder().build();
+   *   Operation response = addressesClient.insert(project, region, addressResource);
+   * }
+   * }
+ * + * @param project Project ID for this request. + * @param region Name of the region for this request. + * @param addressResource The body resource for this request + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Operation insert(String project, String region, Address addressResource) { + InsertAddressRequest request = + InsertAddressRequest.newBuilder() + .setProject(project) + .setRegion(region) + .setAddressResource(addressResource) + .build(); + return insert(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates an address resource in the specified project by using the data included in the request. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   InsertAddressRequest request =
+   *       InsertAddressRequest.newBuilder()
+   *           .setAddressResource(Address.newBuilder().build())
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .setRequestId("requestId693933066")
+   *           .build();
+   *   Operation response = addressesClient.insert(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Operation insert(InsertAddressRequest request) { + return insertCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates an address resource in the specified project by using the data included in the request. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   InsertAddressRequest request =
+   *       InsertAddressRequest.newBuilder()
+   *           .setAddressResource(Address.newBuilder().build())
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .setRequestId("requestId693933066")
+   *           .build();
+   *   ApiFuture future = addressesClient.insertCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable insertCallable() { + return stub.insertCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a list of addresses contained within the specified region. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   String project = "project-309310695";
+   *   String region = "region-934795532";
+   *   String orderBy = "orderBy-1207110587";
+   *   AddressList response = addressesClient.list(project, region, orderBy);
+   * }
+   * }
+ * + * @param project Project ID for this request. + * @param region Name of the region for this request. + * @param orderBy Sorts list results by a certain order. By default, results are returned in + * alphanumerical order based on the resource name. + *

You can also sort results in descending order based on the creation timestamp using + * orderBy="creationTimestamp desc". This sorts results based on the creationTimestamp field + * in reverse chronological order (newest result first). Use this to sort resources like + * operations so that the newest operation is returned first. + *

Currently, only sorting by name or creationTimestamp desc is supported. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AddressList list(String project, String region, String orderBy) { + ListAddressesRequest request = + ListAddressesRequest.newBuilder() + .setProject(project) + .setRegion(region) + .setOrderBy(orderBy) + .build(); + return list(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a list of addresses contained within the specified region. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   ListAddressesRequest request =
+   *       ListAddressesRequest.newBuilder()
+   *           .setFilter("filter-1274492040")
+   *           .setMaxResults(1128457243)
+   *           .setOrderBy("orderBy-1207110587")
+   *           .setPageToken("pageToken873572522")
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .build();
+   *   AddressList response = addressesClient.list(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AddressList list(ListAddressesRequest request) { + return listCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves a list of addresses contained within the specified region. + * + *

Sample code: + * + *

{@code
+   * try (AddressesClient addressesClient = AddressesClient.create()) {
+   *   ListAddressesRequest request =
+   *       ListAddressesRequest.newBuilder()
+   *           .setFilter("filter-1274492040")
+   *           .setMaxResults(1128457243)
+   *           .setOrderBy("orderBy-1207110587")
+   *           .setPageToken("pageToken873572522")
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .build();
+   *   ApiFuture future = addressesClient.listCallable().futureCall(request);
+   *   // Do something.
+   *   AddressList response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable listCallable() { + return stub.listCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesClientTest.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesClientTest.java new file mode 100644 index 0000000000..6f66108448 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesClientTest.java @@ -0,0 +1,314 @@ +/* + * Copyright 2021 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.compute.v1; + +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.compute.v1.stub.HttpJsonAddressesStub; +import java.io.IOException; +import java.util.ArrayList; +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 AddressesClientTest { + private static MockHttpService mockService; + private static AddressesClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAddressesStub.getMethodDescriptors(), AddressesSettings.getDefaultEndpoint()); + AddressesSettings settings = + AddressesSettings.newBuilder() + .setTransportChannelProvider( + AddressesSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AddressesClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void aggregatedListTest() throws Exception { + AddressAggregatedList expectedResponse = + AddressAggregatedList.newBuilder() + .setId("id3355") + .putAllItems(new HashMap()) + .setKind("kind3292052") + .setNextPageToken("nextPageToken-1386094857") + .setSelfLink("selfLink1191800166") + .setWarning(Warning.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String project = "project-309310695"; + + AddressAggregatedList actualResponse = client.aggregatedList(project); + 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 aggregatedListExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String project = "project-309310695"; + client.aggregatedList(project); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteTest() throws Exception { + Operation expectedResponse = + Operation.newBuilder() + .setClientOperationId("clientOperationId-1230366697") + .setCreationTimestamp("creationTimestamp-370203401") + .setDescription("description-1724546052") + .setEndTime("endTime-1607243192") + .setError(Error.newBuilder().build()) + .setHttpErrorMessage("httpErrorMessage1577303431") + .setHttpErrorStatusCode(1386087020) + .setId("id3355") + .setInsertTime("insertTime966165798") + .setKind("kind3292052") + .setName("name3373707") + .setOperationType("operationType91999553") + .setProgress(-1001078227) + .setRegion("region-934795532") + .setSelfLink("selfLink1191800166") + .setStartTime("startTime-2129294769") + .setStatusMessage("statusMessage-958704715") + .setTargetId("targetId-441951604") + .setTargetLink("targetLink486368555") + .setUser("user3599307") + .addAllWarnings(new ArrayList()) + .setZone("zone3744684") + .build(); + mockService.addResponse(expectedResponse); + + String project = "project-309310695"; + String region = "region-934795532"; + String address = "address-1147692044"; + + Operation actualResponse = client.delete(project, region, address); + 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 deleteExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String project = "project-309310695"; + String region = "region-934795532"; + String address = "address-1147692044"; + client.delete(project, region, address); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void insertTest() throws Exception { + Operation expectedResponse = + Operation.newBuilder() + .setClientOperationId("clientOperationId-1230366697") + .setCreationTimestamp("creationTimestamp-370203401") + .setDescription("description-1724546052") + .setEndTime("endTime-1607243192") + .setError(Error.newBuilder().build()) + .setHttpErrorMessage("httpErrorMessage1577303431") + .setHttpErrorStatusCode(1386087020) + .setId("id3355") + .setInsertTime("insertTime966165798") + .setKind("kind3292052") + .setName("name3373707") + .setOperationType("operationType91999553") + .setProgress(-1001078227) + .setRegion("region-934795532") + .setSelfLink("selfLink1191800166") + .setStartTime("startTime-2129294769") + .setStatusMessage("statusMessage-958704715") + .setTargetId("targetId-441951604") + .setTargetLink("targetLink486368555") + .setUser("user3599307") + .addAllWarnings(new ArrayList()) + .setZone("zone3744684") + .build(); + mockService.addResponse(expectedResponse); + + String project = "project-309310695"; + String region = "region-934795532"; + Address addressResource = Address.newBuilder().build(); + + Operation actualResponse = client.insert(project, region, addressResource); + 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 insertExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String project = "project-309310695"; + String region = "region-934795532"; + Address addressResource = Address.newBuilder().build(); + client.insert(project, region, addressResource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listTest() throws Exception { + AddressList expectedResponse = + AddressList.newBuilder() + .setId("id3355") + .addAllItems(new ArrayList
()) + .setKind("kind3292052") + .setNextPageToken("nextPageToken-1386094857") + .setSelfLink("selfLink1191800166") + .setWarning(Warning.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String project = "project-309310695"; + String region = "region-934795532"; + String orderBy = "orderBy-1207110587"; + + AddressList actualResponse = client.list(project, region, orderBy); + 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 listExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String project = "project-309310695"; + String region = "region-934795532"; + String orderBy = "orderBy-1207110587"; + client.list(project, region, orderBy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesSettings.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesSettings.java new file mode 100644 index 0000000000..e7ededa1b4 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/AddressesSettings.java @@ -0,0 +1,214 @@ +/* + * Copyright 2021 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.compute.v1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +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; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.compute.v1.stub.AddressesStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link AddressesClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (compute.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of aggregatedList to 30 seconds: + * + *

{@code
+ * AddressesSettings.Builder addressesSettingsBuilder = AddressesSettings.newBuilder();
+ * addressesSettingsBuilder
+ *     .aggregatedListSettings()
+ *     .setRetrySettings(
+ *         addressesSettingsBuilder
+ *             .aggregatedListSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * AddressesSettings addressesSettings = addressesSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class AddressesSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to aggregatedList. */ + public UnaryCallSettings + aggregatedListSettings() { + return ((AddressesStubSettings) getStubSettings()).aggregatedListSettings(); + } + + /** Returns the object with the settings used for calls to delete. */ + public UnaryCallSettings deleteSettings() { + return ((AddressesStubSettings) getStubSettings()).deleteSettings(); + } + + /** Returns the object with the settings used for calls to insert. */ + public UnaryCallSettings insertSettings() { + return ((AddressesStubSettings) getStubSettings()).insertSettings(); + } + + /** Returns the object with the settings used for calls to list. */ + public UnaryCallSettings listSettings() { + return ((AddressesStubSettings) getStubSettings()).listSettings(); + } + + public static final AddressesSettings create(AddressesStubSettings stub) throws IOException { + return new AddressesSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return AddressesStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return AddressesStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return AddressesStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return AddressesStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AddressesStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return AddressesStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AddressesStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected AddressesSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for AddressesSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(AddressesStubSettings.newBuilder(clientContext)); + } + + protected Builder(AddressesSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(AddressesStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(AddressesStubSettings.newBuilder()); + } + + public AddressesStubSettings.Builder getStubSettingsBuilder() { + return ((AddressesStubSettings.Builder) getStubSettings()); + } + + // NEXT_MAJOR_VER: remove 'throws Exception'. + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to aggregatedList. */ + public UnaryCallSettings.Builder + aggregatedListSettings() { + return getStubSettingsBuilder().aggregatedListSettings(); + } + + /** Returns the builder for the settings used for calls to delete. */ + public UnaryCallSettings.Builder deleteSettings() { + return getStubSettingsBuilder().deleteSettings(); + } + + /** Returns the builder for the settings used for calls to insert. */ + public UnaryCallSettings.Builder insertSettings() { + return getStubSettingsBuilder().insertSettings(); + } + + /** Returns the builder for the settings used for calls to list. */ + public UnaryCallSettings.Builder listSettings() { + return getStubSettingsBuilder().listSettings(); + } + + @Override + public AddressesSettings build() throws IOException { + return new AddressesSettings(this); + } + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsClient.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsClient.java new file mode 100644 index 0000000000..fb6a5e296d --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsClient.java @@ -0,0 +1,254 @@ +/* + * Copyright 2021 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.compute.v1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.compute.v1.stub.RegionOperationsStub; +import com.google.cloud.compute.v1.stub.RegionOperationsStubSettings; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: The RegionOperations API. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * try (RegionOperationsClient regionOperationsClient = RegionOperationsClient.create()) {
+ *   String project = "project-309310695";
+ *   String region = "region-934795532";
+ *   String operation = "operation1662702951";
+ *   Operation response = regionOperationsClient.get(project, region, operation);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the RegionOperationsClient object to clean up resources + * such as threads. In the example above, try-with-resources is used, which automatically calls + * close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of RegionOperationsSettings to + * create(). For example: + * + *

To customize credentials: + * + *

{@code
+ * RegionOperationsSettings regionOperationsSettings =
+ *     RegionOperationsSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * RegionOperationsClient regionOperationsClient =
+ *     RegionOperationsClient.create(regionOperationsSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * RegionOperationsSettings regionOperationsSettings =
+ *     RegionOperationsSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * RegionOperationsClient regionOperationsClient =
+ *     RegionOperationsClient.create(regionOperationsSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@Generated("by gapic-generator-java") +public class RegionOperationsClient implements BackgroundResource { + private final RegionOperationsSettings settings; + private final RegionOperationsStub stub; + + /** Constructs an instance of RegionOperationsClient with default settings. */ + public static final RegionOperationsClient create() throws IOException { + return create(RegionOperationsSettings.newBuilder().build()); + } + + /** + * Constructs an instance of RegionOperationsClient, using the given settings. The channels are + * created based on the settings passed in, or defaults for any settings that are not set. + */ + public static final RegionOperationsClient create(RegionOperationsSettings settings) + throws IOException { + return new RegionOperationsClient(settings); + } + + /** + * Constructs an instance of RegionOperationsClient, using the given stub for making calls. This + * is for advanced usage - prefer using create(RegionOperationsSettings). + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final RegionOperationsClient create(RegionOperationsStub stub) { + return new RegionOperationsClient(stub); + } + + /** + * Constructs an instance of RegionOperationsClient, 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 RegionOperationsClient(RegionOperationsSettings settings) throws IOException { + this.settings = settings; + this.stub = ((RegionOperationsStubSettings) settings.getStubSettings()).createStub(); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected RegionOperationsClient(RegionOperationsStub stub) { + this.settings = null; + this.stub = stub; + } + + public final RegionOperationsSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public RegionOperationsStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the specified region-specific Operations resource. + * + *

Sample code: + * + *

{@code
+   * try (RegionOperationsClient regionOperationsClient = RegionOperationsClient.create()) {
+   *   String project = "project-309310695";
+   *   String region = "region-934795532";
+   *   String operation = "operation1662702951";
+   *   Operation response = regionOperationsClient.get(project, region, operation);
+   * }
+   * }
+ * + * @param project Project ID for this request. + * @param region Name of the region for this request. + * @param operation Name of the Operations resource to return. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Operation get(String project, String region, String operation) { + GetRegionOperationRequest request = + GetRegionOperationRequest.newBuilder() + .setProject(project) + .setRegion(region) + .setOperation(operation) + .build(); + return get(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the specified region-specific Operations resource. + * + *

Sample code: + * + *

{@code
+   * try (RegionOperationsClient regionOperationsClient = RegionOperationsClient.create()) {
+   *   GetRegionOperationRequest request =
+   *       GetRegionOperationRequest.newBuilder()
+   *           .setOperation("operation1662702951")
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .build();
+   *   Operation response = regionOperationsClient.get(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Operation get(GetRegionOperationRequest request) { + return getCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Retrieves the specified region-specific Operations resource. + * + *

Sample code: + * + *

{@code
+   * try (RegionOperationsClient regionOperationsClient = RegionOperationsClient.create()) {
+   *   GetRegionOperationRequest request =
+   *       GetRegionOperationRequest.newBuilder()
+   *           .setOperation("operation1662702951")
+   *           .setProject("project-309310695")
+   *           .setRegion("region-934795532")
+   *           .build();
+   *   ApiFuture future = regionOperationsClient.getCallable().futureCall(request);
+   *   // Do something.
+   *   Operation response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getCallable() { + return stub.getCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsClientTest.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsClientTest.java new file mode 100644 index 0000000000..7f6b78232a --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsClientTest.java @@ -0,0 +1,143 @@ +/* + * Copyright 2021 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.compute.v1; + +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.compute.v1.stub.HttpJsonRegionOperationsStub; +import java.io.IOException; +import java.util.ArrayList; +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 RegionOperationsClientTest { + private static MockHttpService mockService; + private static RegionOperationsClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonRegionOperationsStub.getMethodDescriptors(), + RegionOperationsSettings.getDefaultEndpoint()); + RegionOperationsSettings settings = + RegionOperationsSettings.newBuilder() + .setTransportChannelProvider( + RegionOperationsSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = RegionOperationsClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void getTest() throws Exception { + Operation expectedResponse = + Operation.newBuilder() + .setClientOperationId("clientOperationId-1230366697") + .setCreationTimestamp("creationTimestamp-370203401") + .setDescription("description-1724546052") + .setEndTime("endTime-1607243192") + .setError(Error.newBuilder().build()) + .setHttpErrorMessage("httpErrorMessage1577303431") + .setHttpErrorStatusCode(1386087020) + .setId("id3355") + .setInsertTime("insertTime966165798") + .setKind("kind3292052") + .setName("name3373707") + .setOperationType("operationType91999553") + .setProgress(-1001078227) + .setRegion("region-934795532") + .setSelfLink("selfLink1191800166") + .setStartTime("startTime-2129294769") + .setStatusMessage("statusMessage-958704715") + .setTargetId("targetId-441951604") + .setTargetLink("targetLink486368555") + .setUser("user3599307") + .addAllWarnings(new ArrayList()) + .setZone("zone3744684") + .build(); + mockService.addResponse(expectedResponse); + + String project = "project-309310695"; + String region = "region-934795532"; + String operation = "operation1662702951"; + + Operation actualResponse = client.get(project, region, operation); + 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 getExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String project = "project-309310695"; + String region = "region-934795532"; + String operation = "operation1662702951"; + client.get(project, region, operation); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsSettings.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsSettings.java new file mode 100644 index 0000000000..2244662817 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/RegionOperationsSettings.java @@ -0,0 +1,184 @@ +/* + * Copyright 2021 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.compute.v1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +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; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.compute.v1.stub.RegionOperationsStubSettings; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link RegionOperationsClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (compute.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of get to 30 seconds: + * + *

{@code
+ * RegionOperationsSettings.Builder regionOperationsSettingsBuilder =
+ *     RegionOperationsSettings.newBuilder();
+ * regionOperationsSettingsBuilder
+ *     .getSettings()
+ *     .setRetrySettings(
+ *         regionOperationsSettingsBuilder
+ *             .getSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * RegionOperationsSettings regionOperationsSettings = regionOperationsSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class RegionOperationsSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to get. */ + public UnaryCallSettings getSettings() { + return ((RegionOperationsStubSettings) getStubSettings()).getSettings(); + } + + public static final RegionOperationsSettings create(RegionOperationsStubSettings stub) + throws IOException { + return new RegionOperationsSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return RegionOperationsStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return RegionOperationsStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return RegionOperationsStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return RegionOperationsStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return RegionOperationsStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return RegionOperationsStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return RegionOperationsStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected RegionOperationsSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for RegionOperationsSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(RegionOperationsStubSettings.newBuilder(clientContext)); + } + + protected Builder(RegionOperationsSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(RegionOperationsStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(RegionOperationsStubSettings.newBuilder()); + } + + public RegionOperationsStubSettings.Builder getStubSettingsBuilder() { + return ((RegionOperationsStubSettings.Builder) getStubSettings()); + } + + // NEXT_MAJOR_VER: remove 'throws Exception'. + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to get. */ + public UnaryCallSettings.Builder getSettings() { + return getStubSettingsBuilder().getSettings(); + } + + @Override + public RegionOperationsSettings build() throws IOException { + return new RegionOperationsSettings(this); + } + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/gapic_metadata.json b/test/integration/goldens/compute/com/google/cloud/compute/v1/gapic_metadata.json new file mode 100644 index 0000000000..3d8eb8ed66 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/gapic_metadata.json @@ -0,0 +1,42 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "java", + "protoPackage": "google.cloud.compute.v1", + "libraryPackage": "com.google.cloud.compute.v1", + "services": { + "Addresses": { + "clients": { + "grpc": { + "libraryClient": "AddressesClient", + "rpcs": { + "AggregatedList": { + "methods": ["aggregatedList", "aggregatedList", "aggregatedListCallable"] + }, + "Delete": { + "methods": ["delete", "delete", "deleteCallable"] + }, + "Insert": { + "methods": ["insert", "insert", "insertCallable"] + }, + "List": { + "methods": ["list", "list", "listCallable"] + } + } + } + } + }, + "RegionOperations": { + "clients": { + "grpc": { + "libraryClient": "RegionOperationsClient", + "rpcs": { + "Get": { + "methods": ["get", "get", "getCallable"] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/package-info.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/package-info.java new file mode 100644 index 0000000000..fbc46c7bdc --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/package-info.java @@ -0,0 +1,53 @@ +/* + * Copyright 2021 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. + */ + +/** + * The interfaces provided are listed below, along with usage samples. + * + *

======================= AddressesClient ======================= + * + *

Service Description: Services + * + *

The Addresses API. + * + *

Sample for AddressesClient: + * + *

{@code
+ * try (AddressesClient addressesClient = AddressesClient.create()) {
+ *   String project = "project-309310695";
+ *   AddressAggregatedList response = addressesClient.aggregatedList(project);
+ * }
+ * }
+ * + *

======================= RegionOperationsClient ======================= + * + *

Service Description: The RegionOperations API. + * + *

Sample for RegionOperationsClient: + * + *

{@code
+ * try (RegionOperationsClient regionOperationsClient = RegionOperationsClient.create()) {
+ *   String project = "project-309310695";
+ *   String region = "region-934795532";
+ *   String operation = "operation1662702951";
+ *   Operation response = regionOperationsClient.get(project, region, operation);
+ * }
+ * }
+ */ +@Generated("by gapic-generator-java") +package com.google.cloud.compute.v1; + +import javax.annotation.Generated; diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStub.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStub.java new file mode 100644 index 0000000000..d192131a5b --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStub.java @@ -0,0 +1,58 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.compute.v1.AddressAggregatedList; +import com.google.cloud.compute.v1.AddressList; +import com.google.cloud.compute.v1.AggregatedListAddressesRequest; +import com.google.cloud.compute.v1.DeleteAddressRequest; +import com.google.cloud.compute.v1.InsertAddressRequest; +import com.google.cloud.compute.v1.ListAddressesRequest; +import com.google.cloud.compute.v1.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Addresses service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +public abstract class AddressesStub implements BackgroundResource { + + public UnaryCallable + aggregatedListCallable() { + throw new UnsupportedOperationException("Not implemented: aggregatedListCallable()"); + } + + public UnaryCallable deleteCallable() { + throw new UnsupportedOperationException("Not implemented: deleteCallable()"); + } + + public UnaryCallable insertCallable() { + throw new UnsupportedOperationException("Not implemented: insertCallable()"); + } + + public UnaryCallable listCallable() { + throw new UnsupportedOperationException("Not implemented: listCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java new file mode 100644 index 0000000000..d8268b878b --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java @@ -0,0 +1,334 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +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.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.compute.v1.AddressAggregatedList; +import com.google.cloud.compute.v1.AddressList; +import com.google.cloud.compute.v1.AggregatedListAddressesRequest; +import com.google.cloud.compute.v1.DeleteAddressRequest; +import com.google.cloud.compute.v1.InsertAddressRequest; +import com.google.cloud.compute.v1.ListAddressesRequest; +import com.google.cloud.compute.v1.Operation; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link AddressesStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (compute.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of aggregatedList to 30 seconds: + * + *

{@code
+ * AddressesStubSettings.Builder addressesSettingsBuilder = AddressesStubSettings.newBuilder();
+ * addressesSettingsBuilder
+ *     .aggregatedListSettings()
+ *     .setRetrySettings(
+ *         addressesSettingsBuilder
+ *             .aggregatedListSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * AddressesStubSettings addressesSettings = addressesSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class AddressesStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/compute") + .add("https://www.googleapis.com/auth/cloud-platform") + .build(); + + private final UnaryCallSettings + aggregatedListSettings; + private final UnaryCallSettings deleteSettings; + private final UnaryCallSettings insertSettings; + private final UnaryCallSettings listSettings; + + /** Returns the object with the settings used for calls to aggregatedList. */ + public UnaryCallSettings + aggregatedListSettings() { + return aggregatedListSettings; + } + + /** Returns the object with the settings used for calls to delete. */ + public UnaryCallSettings deleteSettings() { + return deleteSettings; + } + + /** Returns the object with the settings used for calls to insert. */ + public UnaryCallSettings insertSettings() { + return insertSettings; + } + + /** Returns the object with the settings used for calls to list. */ + public UnaryCallSettings listSettings() { + return listSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public AddressesStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAddressesStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "compute.googleapis.com:443"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "compute.mtls.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultHttpJsonTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(AddressesStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected AddressesStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + aggregatedListSettings = settingsBuilder.aggregatedListSettings().build(); + deleteSettings = settingsBuilder.deleteSettings().build(); + insertSettings = settingsBuilder.insertSettings().build(); + listSettings = settingsBuilder.listSettings().build(); + } + + /** Builder for AddressesStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder + aggregatedListSettings; + private final UnaryCallSettings.Builder deleteSettings; + private final UnaryCallSettings.Builder insertSettings; + private final UnaryCallSettings.Builder listSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + aggregatedListSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + deleteSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + insertSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + listSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + aggregatedListSettings, deleteSettings, insertSettings, listSettings); + initDefaults(this); + } + + protected Builder(AddressesStubSettings settings) { + super(settings); + + aggregatedListSettings = settings.aggregatedListSettings.toBuilder(); + deleteSettings = settings.deleteSettings.toBuilder(); + insertSettings = settings.insertSettings.toBuilder(); + listSettings = settings.listSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + aggregatedListSettings, deleteSettings, insertSettings, listSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .aggregatedListSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .deleteSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .insertSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .listSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + // NEXT_MAJOR_VER: remove 'throws Exception'. + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to aggregatedList. */ + public UnaryCallSettings.Builder + aggregatedListSettings() { + return aggregatedListSettings; + } + + /** Returns the builder for the settings used for calls to delete. */ + public UnaryCallSettings.Builder deleteSettings() { + return deleteSettings; + } + + /** Returns the builder for the settings used for calls to insert. */ + public UnaryCallSettings.Builder insertSettings() { + return insertSettings; + } + + /** Returns the builder for the settings used for calls to list. */ + public UnaryCallSettings.Builder listSettings() { + return listSettings; + } + + @Override + public AddressesStubSettings build() throws IOException { + return new AddressesStubSettings(this); + } + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesCallableFactory.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesCallableFactory.java new file mode 100644 index 0000000000..98f81444ec --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesCallableFactory.java @@ -0,0 +1,80 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.ApiMessage; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +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.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Addresses service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +public class HttpJsonAddressesCallableFactory + 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); + } + + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + BackgroundResource operationsStub) { + return null; + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesStub.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesStub.java new file mode 100644 index 0000000000..eeb7b31c69 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesStub.java @@ -0,0 +1,389 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.client.http.HttpMethods; +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.FieldsExtractor; +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.compute.v1.AddressAggregatedList; +import com.google.cloud.compute.v1.AddressList; +import com.google.cloud.compute.v1.AggregatedListAddressesRequest; +import com.google.cloud.compute.v1.DeleteAddressRequest; +import com.google.cloud.compute.v1.InsertAddressRequest; +import com.google.cloud.compute.v1.ListAddressesRequest; +import com.google.cloud.compute.v1.Operation; +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 Addresses service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class HttpJsonAddressesStub extends AddressesStub { + private static final ApiMethodDescriptor + aggregatedListMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.compute.v1.Addresses/AggregatedList") + .setHttpMethod(HttpMethods.GET) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/compute/v1/projects/{project}/aggregated/addresses", + new FieldsExtractor< + AggregatedListAddressesRequest, Map>() { + @Override + public Map extract( + AggregatedListAddressesRequest request) { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "project", request.getProject()); + return fields; + } + }) + .setQueryParamsExtractor( + new FieldsExtractor< + AggregatedListAddressesRequest, Map>>() { + @Override + public Map> extract( + AggregatedListAddressesRequest request) { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam( + fields, "includeAllScopes", request.getIncludeAllScopes()); + serializer.putQueryParam( + fields, "maxResults", request.getMaxResults()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + } + }) + .setRequestBodyExtractor( + new FieldsExtractor() { + @Override + public String extract(AggregatedListAddressesRequest request) { + return null; + } + }) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AddressAggregatedList.getDefaultInstance()) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.compute.v1.Addresses/Delete") + .setHttpMethod(HttpMethods.DELETE) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/compute/v1/projects/{project}/regions/{region}/addresses/{address}", + new FieldsExtractor>() { + @Override + public Map extract(DeleteAddressRequest request) { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "address", request.getAddress()); + serializer.putPathParam(fields, "project", request.getProject()); + serializer.putPathParam(fields, "region", request.getRegion()); + return fields; + } + }) + .setQueryParamsExtractor( + new FieldsExtractor>>() { + @Override + public Map> extract(DeleteAddressRequest request) { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "requestId", request.getRequestId()); + return fields; + } + }) + .setRequestBodyExtractor( + new FieldsExtractor() { + @Override + public String extract(DeleteAddressRequest request) { + return null; + } + }) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .build()) + .build(); + + private static final ApiMethodDescriptor insertMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.compute.v1.Addresses/Insert") + .setHttpMethod(HttpMethods.POST) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/compute/v1/projects/{project}/regions/{region}/addresses", + new FieldsExtractor>() { + @Override + public Map extract(InsertAddressRequest request) { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "project", request.getProject()); + serializer.putPathParam(fields, "region", request.getRegion()); + return fields; + } + }) + .setQueryParamsExtractor( + new FieldsExtractor>>() { + @Override + public Map> extract(InsertAddressRequest request) { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "requestId", request.getRequestId()); + return fields; + } + }) + .setRequestBodyExtractor( + new FieldsExtractor() { + @Override + public String extract(InsertAddressRequest request) { + return ProtoRestSerializer.create() + .toBody("addressResource", request.getAddressResource()); + } + }) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .build()) + .build(); + + private static final ApiMethodDescriptor listMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.compute.v1.Addresses/List") + .setHttpMethod(HttpMethods.GET) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/compute/v1/projects/{project}/regions/{region}/addresses", + new FieldsExtractor>() { + @Override + public Map extract(ListAddressesRequest request) { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "project", request.getProject()); + serializer.putPathParam(fields, "region", request.getRegion()); + return fields; + } + }) + .setQueryParamsExtractor( + new FieldsExtractor>>() { + @Override + public Map> extract(ListAddressesRequest request) { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "maxResults", request.getMaxResults()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + } + }) + .setRequestBodyExtractor( + new FieldsExtractor() { + @Override + public String extract(ListAddressesRequest request) { + return null; + } + }) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AddressList.getDefaultInstance()) + .build()) + .build(); + + private final UnaryCallable + aggregatedListCallable; + private final UnaryCallable deleteCallable; + private final UnaryCallable insertCallable; + private final UnaryCallable listCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAddressesStub create(AddressesStubSettings settings) + throws IOException { + return new HttpJsonAddressesStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAddressesStub create(ClientContext clientContext) throws IOException { + return new HttpJsonAddressesStub(AddressesStubSettings.newBuilder().build(), clientContext); + } + + public static final HttpJsonAddressesStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAddressesStub( + AddressesStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAddressesStub, 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 HttpJsonAddressesStub(AddressesStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAddressesCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAddressesStub, 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 HttpJsonAddressesStub( + AddressesStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + aggregatedListTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(aggregatedListMethodDescriptor) + .build(); + HttpJsonCallSettings deleteTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteMethodDescriptor) + .build(); + HttpJsonCallSettings insertTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(insertMethodDescriptor) + .build(); + HttpJsonCallSettings listTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listMethodDescriptor) + .build(); + + this.aggregatedListCallable = + callableFactory.createUnaryCallable( + aggregatedListTransportSettings, settings.aggregatedListSettings(), clientContext); + this.deleteCallable = + callableFactory.createUnaryCallable( + deleteTransportSettings, settings.deleteSettings(), clientContext); + this.insertCallable = + callableFactory.createUnaryCallable( + insertTransportSettings, settings.insertSettings(), clientContext); + this.listCallable = + callableFactory.createUnaryCallable( + listTransportSettings, settings.listSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(aggregatedListMethodDescriptor); + methodDescriptors.add(deleteMethodDescriptor); + methodDescriptors.add(insertMethodDescriptor); + methodDescriptors.add(listMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + aggregatedListCallable() { + return aggregatedListCallable; + } + + @Override + public UnaryCallable deleteCallable() { + return deleteCallable; + } + + @Override + public UnaryCallable insertCallable() { + return insertCallable; + } + + @Override + public UnaryCallable listCallable() { + return listCallable; + } + + @Override + public final void close() { + shutdown(); + } + + @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/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsCallableFactory.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsCallableFactory.java new file mode 100644 index 0000000000..2694d1aa62 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsCallableFactory.java @@ -0,0 +1,80 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.ApiMessage; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +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.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the RegionOperations service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +public class HttpJsonRegionOperationsCallableFactory + 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); + } + + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + BackgroundResource operationsStub) { + return null; + } +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsStub.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsStub.java new file mode 100644 index 0000000000..0be8cf4d03 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsStub.java @@ -0,0 +1,197 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.client.http.HttpMethods; +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.FieldsExtractor; +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.compute.v1.GetRegionOperationRequest; +import com.google.cloud.compute.v1.Operation; +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 RegionOperations service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class HttpJsonRegionOperationsStub extends RegionOperationsStub { + private static final ApiMethodDescriptor + getMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.compute.v1.RegionOperations/Get") + .setHttpMethod(HttpMethods.GET) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/compute/v1/projects/{project}/regions/{region}/operations/{operation}", + new FieldsExtractor>() { + @Override + public Map extract(GetRegionOperationRequest request) { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "operation", request.getOperation()); + serializer.putPathParam(fields, "project", request.getProject()); + serializer.putPathParam(fields, "region", request.getRegion()); + return fields; + } + }) + .setQueryParamsExtractor( + new FieldsExtractor< + GetRegionOperationRequest, Map>>() { + @Override + public Map> extract( + GetRegionOperationRequest request) { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + } + }) + .setRequestBodyExtractor( + new FieldsExtractor() { + @Override + public String extract(GetRegionOperationRequest request) { + return null; + } + }) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .build()) + .build(); + + private final UnaryCallable getCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonRegionOperationsStub create(RegionOperationsStubSettings settings) + throws IOException { + return new HttpJsonRegionOperationsStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonRegionOperationsStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonRegionOperationsStub( + RegionOperationsStubSettings.newBuilder().build(), clientContext); + } + + public static final HttpJsonRegionOperationsStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonRegionOperationsStub( + RegionOperationsStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonRegionOperationsStub, 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 HttpJsonRegionOperationsStub( + RegionOperationsStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonRegionOperationsCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonRegionOperationsStub, 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 HttpJsonRegionOperationsStub( + RegionOperationsStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings getTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getMethodDescriptor) + .build(); + + this.getCallable = + callableFactory.createUnaryCallable( + getTransportSettings, settings.getSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(getMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable getCallable() { + return getCallable; + } + + @Override + public final void close() { + shutdown(); + } + + @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/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStub.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStub.java new file mode 100644 index 0000000000..c3019038cb --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStub.java @@ -0,0 +1,40 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.compute.v1.GetRegionOperationRequest; +import com.google.cloud.compute.v1.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the RegionOperations service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +public abstract class RegionOperationsStub implements BackgroundResource { + + public UnaryCallable getCallable() { + throw new UnsupportedOperationException("Not implemented: getCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java new file mode 100644 index 0000000000..25be522d20 --- /dev/null +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java @@ -0,0 +1,264 @@ +/* + * Copyright 2021 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.compute.v1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +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.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.compute.v1.GetRegionOperationRequest; +import com.google.cloud.compute.v1.Operation; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link RegionOperationsStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (compute.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of get to 30 seconds: + * + *

{@code
+ * RegionOperationsStubSettings.Builder regionOperationsSettingsBuilder =
+ *     RegionOperationsStubSettings.newBuilder();
+ * regionOperationsSettingsBuilder
+ *     .getSettings()
+ *     .setRetrySettings(
+ *         regionOperationsSettingsBuilder
+ *             .getSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * RegionOperationsStubSettings regionOperationsSettings = regionOperationsSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class RegionOperationsStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/compute.readonly") + .add("https://www.googleapis.com/auth/compute") + .add("https://www.googleapis.com/auth/cloud-platform") + .build(); + + private final UnaryCallSettings getSettings; + + /** Returns the object with the settings used for calls to get. */ + public UnaryCallSettings getSettings() { + return getSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public RegionOperationsStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonRegionOperationsStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "compute.googleapis.com:443"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "compute.mtls.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultHttpJsonTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(RegionOperationsStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected RegionOperationsStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + getSettings = settingsBuilder.getSettings().build(); + } + + /** Builder for RegionOperationsStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder getSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + getSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = ImmutableList.>of(getSettings); + initDefaults(this); + } + + protected Builder(RegionOperationsStubSettings settings) { + super(settings); + + getSettings = settings.getSettings.toBuilder(); + + unaryMethodSettingsBuilders = ImmutableList.>of(getSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .getSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + // NEXT_MAJOR_VER: remove 'throws Exception'. + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to get. */ + public UnaryCallSettings.Builder getSettings() { + return getSettings; + } + + @Override + public RegionOperationsStubSettings build() throws IOException { + return new RegionOperationsStubSettings(this); + } + } +} diff --git a/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClient.java b/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClient.java index a1dad2c9c7..df3a63cfff 100644 --- a/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClient.java +++ b/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClient.java @@ -47,6 +47,7 @@ import com.google.example.library.v1.ShelfName; import com.google.example.library.v1.UpdateBookRequest; import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -264,7 +265,7 @@ public final Shelf getShelf(ShelfName name) { * *

{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
+   *   String name = ShelfName.of("[SHELF_ID]").toString();
    *   Shelf response = libraryServiceClient.getShelf(name);
    * }
    * }
@@ -285,7 +286,8 @@ public final Shelf getShelf(String name) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   GetShelfRequest request = GetShelfRequest.newBuilder().setName("name3373707").build();
+   *   GetShelfRequest request =
+   *       GetShelfRequest.newBuilder().setName(ShelfName.of("[SHELF_ID]").toString()).build();
    *   Shelf response = libraryServiceClient.getShelf(request);
    * }
    * }
@@ -305,7 +307,8 @@ public final Shelf getShelf(GetShelfRequest request) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   GetShelfRequest request = GetShelfRequest.newBuilder().setName("name3373707").build();
+   *   GetShelfRequest request =
+   *       GetShelfRequest.newBuilder().setName(ShelfName.of("[SHELF_ID]").toString()).build();
    *   ApiFuture future = libraryServiceClient.getShelfCallable().futureCall(request);
    *   // Do something.
    *   Shelf response = future.get();
@@ -433,7 +436,7 @@ public final void deleteShelf(ShelfName name) {
    *
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
+   *   String name = ShelfName.of("[SHELF_ID]").toString();
    *   libraryServiceClient.deleteShelf(name);
    * }
    * }
@@ -454,7 +457,8 @@ public final void deleteShelf(String name) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   DeleteShelfRequest request = DeleteShelfRequest.newBuilder().setName("name3373707").build();
+   *   DeleteShelfRequest request =
+   *       DeleteShelfRequest.newBuilder().setName(ShelfName.of("[SHELF_ID]").toString()).build();
    *   libraryServiceClient.deleteShelf(request);
    * }
    * }
@@ -474,7 +478,8 @@ public final void deleteShelf(DeleteShelfRequest request) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   DeleteShelfRequest request = DeleteShelfRequest.newBuilder().setName("name3373707").build();
+   *   DeleteShelfRequest request =
+   *       DeleteShelfRequest.newBuilder().setName(ShelfName.of("[SHELF_ID]").toString()).build();
    *   ApiFuture future = libraryServiceClient.deleteShelfCallable().futureCall(request);
    *   // Do something.
    *   future.get();
@@ -499,20 +504,20 @@ public final UnaryCallable deleteShelfCallable() {
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
    *   ShelfName name = ShelfName.of("[SHELF_ID]");
-   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
-   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   *   ShelfName otherShelf = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelf);
    * }
    * }
* * @param name The name of the shelf we're adding books to. - * @param otherShelfName The name of the shelf we're removing books from and deleting. + * @param otherShelf The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Shelf mergeShelves(ShelfName name, ShelfName otherShelfName) { + public final Shelf mergeShelves(ShelfName name, ShelfName otherShelf) { MergeShelvesRequest request = MergeShelvesRequest.newBuilder() .setName(name == null ? null : name.toString()) - .setOtherShelfName(otherShelfName == null ? null : otherShelfName.toString()) + .setOtherShelf(otherShelf == null ? null : otherShelf.toString()) .build(); return mergeShelves(request); } @@ -531,20 +536,20 @@ public final Shelf mergeShelves(ShelfName name, ShelfName otherShelfName) { *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
    *   ShelfName name = ShelfName.of("[SHELF_ID]");
-   *   String otherShelfName = "otherShelfName-1942963547";
-   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   *   String otherShelf = ShelfName.of("[SHELF_ID]").toString();
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelf);
    * }
    * }
* * @param name The name of the shelf we're adding books to. - * @param otherShelfName The name of the shelf we're removing books from and deleting. + * @param otherShelf The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Shelf mergeShelves(ShelfName name, String otherShelfName) { + public final Shelf mergeShelves(ShelfName name, String otherShelf) { MergeShelvesRequest request = MergeShelvesRequest.newBuilder() .setName(name == null ? null : name.toString()) - .setOtherShelfName(otherShelfName) + .setOtherShelf(otherShelf) .build(); return mergeShelves(request); } @@ -562,21 +567,21 @@ public final Shelf mergeShelves(ShelfName name, String otherShelfName) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
-   *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
-   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   *   String name = ShelfName.of("[SHELF_ID]").toString();
+   *   ShelfName otherShelf = ShelfName.of("[SHELF_ID]");
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelf);
    * }
    * }
* * @param name The name of the shelf we're adding books to. - * @param otherShelfName The name of the shelf we're removing books from and deleting. + * @param otherShelf The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Shelf mergeShelves(String name, ShelfName otherShelfName) { + public final Shelf mergeShelves(String name, ShelfName otherShelf) { MergeShelvesRequest request = MergeShelvesRequest.newBuilder() .setName(name) - .setOtherShelfName(otherShelfName == null ? null : otherShelfName.toString()) + .setOtherShelf(otherShelf == null ? null : otherShelf.toString()) .build(); return mergeShelves(request); } @@ -594,19 +599,19 @@ public final Shelf mergeShelves(String name, ShelfName otherShelfName) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
-   *   String otherShelfName = "otherShelfName-1942963547";
-   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelfName);
+   *   String name = ShelfName.of("[SHELF_ID]").toString();
+   *   String otherShelf = ShelfName.of("[SHELF_ID]").toString();
+   *   Shelf response = libraryServiceClient.mergeShelves(name, otherShelf);
    * }
    * }
* * @param name The name of the shelf we're adding books to. - * @param otherShelfName The name of the shelf we're removing books from and deleting. + * @param otherShelf The name of the shelf we're removing books from and deleting. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Shelf mergeShelves(String name, String otherShelfName) { + public final Shelf mergeShelves(String name, String otherShelf) { MergeShelvesRequest request = - MergeShelvesRequest.newBuilder().setName(name).setOtherShelfName(otherShelfName).build(); + MergeShelvesRequest.newBuilder().setName(name).setOtherShelf(otherShelf).build(); return mergeShelves(request); } @@ -625,8 +630,8 @@ public final Shelf mergeShelves(String name, String otherShelfName) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * MergeShelvesRequest request = * MergeShelvesRequest.newBuilder() - * .setName("name3373707") - * .setOtherShelfName("otherShelfName-1942963547") + * .setName(ShelfName.of("[SHELF_ID]").toString()) + * .setOtherShelf(ShelfName.of("[SHELF_ID]").toString()) * .build(); * Shelf response = libraryServiceClient.mergeShelves(request); * } @@ -654,8 +659,8 @@ public final Shelf mergeShelves(MergeShelvesRequest request) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * MergeShelvesRequest request = * MergeShelvesRequest.newBuilder() - * .setName("name3373707") - * .setOtherShelfName("otherShelfName-1942963547") + * .setName(ShelfName.of("[SHELF_ID]").toString()) + * .setOtherShelf(ShelfName.of("[SHELF_ID]").toString()) * .build(); * ApiFuture future = libraryServiceClient.mergeShelvesCallable().futureCall(request); * // Do something. @@ -675,20 +680,20 @@ public final UnaryCallable mergeShelvesCallable() { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   ShelfName name = ShelfName.of("[SHELF_ID]");
+   *   ShelfName parent = ShelfName.of("[SHELF_ID]");
    *   Book book = Book.newBuilder().build();
-   *   Book response = libraryServiceClient.createBook(name, book);
+   *   Book response = libraryServiceClient.createBook(parent, book);
    * }
    * }
* - * @param name The name of the shelf in which the book is created. + * @param parent The name of the shelf in which the book is created. * @param book The book to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Book createBook(ShelfName name, Book book) { + public final Book createBook(ShelfName parent, Book book) { CreateBookRequest request = CreateBookRequest.newBuilder() - .setName(name == null ? null : name.toString()) + .setParent(parent == null ? null : parent.toString()) .setBook(book) .build(); return createBook(request); @@ -702,18 +707,19 @@ public final Book createBook(ShelfName name, Book book) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
+   *   String parent = ShelfName.of("[SHELF_ID]").toString();
    *   Book book = Book.newBuilder().build();
-   *   Book response = libraryServiceClient.createBook(name, book);
+   *   Book response = libraryServiceClient.createBook(parent, book);
    * }
    * }
* - * @param name The name of the shelf in which the book is created. + * @param parent The name of the shelf in which the book is created. * @param book The book to create. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Book createBook(String name, Book book) { - CreateBookRequest request = CreateBookRequest.newBuilder().setName(name).setBook(book).build(); + public final Book createBook(String parent, Book book) { + CreateBookRequest request = + CreateBookRequest.newBuilder().setParent(parent).setBook(book).build(); return createBook(request); } @@ -727,7 +733,7 @@ public final Book createBook(String name, Book book) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * CreateBookRequest request = * CreateBookRequest.newBuilder() - * .setName("name3373707") + * .setParent(ShelfName.of("[SHELF_ID]").toString()) * .setBook(Book.newBuilder().build()) * .build(); * Book response = libraryServiceClient.createBook(request); @@ -751,7 +757,7 @@ public final Book createBook(CreateBookRequest request) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * CreateBookRequest request = * CreateBookRequest.newBuilder() - * .setName("name3373707") + * .setParent(ShelfName.of("[SHELF_ID]").toString()) * .setBook(Book.newBuilder().build()) * .build(); * ApiFuture future = libraryServiceClient.createBookCallable().futureCall(request); @@ -772,7 +778,7 @@ public final UnaryCallable createBookCallable() { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   BookName name = BookName.of("[SHELF]", "[BOOK]");
    *   Book response = libraryServiceClient.getBook(name);
    * }
    * }
@@ -794,7 +800,7 @@ public final Book getBook(BookName name) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
+   *   String name = BookName.of("[SHELF]", "[BOOK]").toString();
    *   Book response = libraryServiceClient.getBook(name);
    * }
    * }
@@ -815,7 +821,8 @@ public final Book getBook(String name) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   GetBookRequest request = GetBookRequest.newBuilder().setName("name3373707").build();
+   *   GetBookRequest request =
+   *       GetBookRequest.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).build();
    *   Book response = libraryServiceClient.getBook(request);
    * }
    * }
@@ -835,7 +842,8 @@ public final Book getBook(GetBookRequest request) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   GetBookRequest request = GetBookRequest.newBuilder().setName("name3373707").build();
+   *   GetBookRequest request =
+   *       GetBookRequest.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).build();
    *   ApiFuture future = libraryServiceClient.getBookCallable().futureCall(request);
    *   // Do something.
    *   Book response = future.get();
@@ -856,19 +864,19 @@ public final UnaryCallable getBookCallable() {
    *
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   ShelfName name = ShelfName.of("[SHELF_ID]");
-   *   for (Book element : libraryServiceClient.listBooks(name).iterateAll()) {
+   *   ShelfName parent = ShelfName.of("[SHELF_ID]");
+   *   for (Book element : libraryServiceClient.listBooks(parent).iterateAll()) {
    *     // doThingsWith(element);
    *   }
    * }
    * }
* - * @param name The name of the shelf whose books we'd like to list. + * @param parent The name of the shelf whose books we'd like to list. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final ListBooksPagedResponse listBooks(ShelfName name) { + public final ListBooksPagedResponse listBooks(ShelfName parent) { ListBooksRequest request = - ListBooksRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + ListBooksRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); return listBooks(request); } @@ -882,18 +890,18 @@ public final ListBooksPagedResponse listBooks(ShelfName name) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
-   *   for (Book element : libraryServiceClient.listBooks(name).iterateAll()) {
+   *   String parent = ShelfName.of("[SHELF_ID]").toString();
+   *   for (Book element : libraryServiceClient.listBooks(parent).iterateAll()) {
    *     // doThingsWith(element);
    *   }
    * }
    * }
* - * @param name The name of the shelf whose books we'd like to list. + * @param parent The name of the shelf whose books we'd like to list. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final ListBooksPagedResponse listBooks(String name) { - ListBooksRequest request = ListBooksRequest.newBuilder().setName(name).build(); + public final ListBooksPagedResponse listBooks(String parent) { + ListBooksRequest request = ListBooksRequest.newBuilder().setParent(parent).build(); return listBooks(request); } @@ -909,7 +917,7 @@ public final ListBooksPagedResponse listBooks(String name) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * ListBooksRequest request = * ListBooksRequest.newBuilder() - * .setName("name3373707") + * .setParent(ShelfName.of("[SHELF_ID]").toString()) * .setPageSize(883849137) * .setPageToken("pageToken873572522") * .build(); @@ -938,7 +946,7 @@ public final ListBooksPagedResponse listBooks(ListBooksRequest request) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * ListBooksRequest request = * ListBooksRequest.newBuilder() - * .setName("name3373707") + * .setParent(ShelfName.of("[SHELF_ID]").toString()) * .setPageSize(883849137) * .setPageToken("pageToken873572522") * .build(); @@ -966,7 +974,7 @@ public final UnaryCallable listBooksPa * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * ListBooksRequest request = * ListBooksRequest.newBuilder() - * .setName("name3373707") + * .setParent(ShelfName.of("[SHELF_ID]").toString()) * .setPageSize(883849137) * .setPageToken("pageToken873572522") * .build(); @@ -997,7 +1005,53 @@ public final UnaryCallable listBooksCallabl * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   DeleteBookRequest request = DeleteBookRequest.newBuilder().setName("name3373707").build();
+   *   BookName name = BookName.of("[SHELF]", "[BOOK]");
+   *   libraryServiceClient.deleteBook(name);
+   * }
+   * }
+ * + * @param name The name of the book to delete. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBook(BookName name) { + DeleteBookRequest request = + DeleteBookRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + deleteBook(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a book. Returns NOT_FOUND if the book does not exist. + * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   String name = BookName.of("[SHELF]", "[BOOK]").toString();
+   *   libraryServiceClient.deleteBook(name);
+   * }
+   * }
+ * + * @param name The name of the book to delete. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final void deleteBook(String name) { + DeleteBookRequest request = DeleteBookRequest.newBuilder().setName(name).build(); + deleteBook(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Deletes a book. Returns NOT_FOUND if the book does not exist. + * + *

Sample code: + * + *

{@code
+   * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
+   *   DeleteBookRequest request =
+   *       DeleteBookRequest.newBuilder()
+   *           .setName(BookName.of("[SHELF]", "[BOOK]").toString())
+   *           .build();
    *   libraryServiceClient.deleteBook(request);
    * }
    * }
@@ -1017,7 +1071,10 @@ public final void deleteBook(DeleteBookRequest request) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   DeleteBookRequest request = DeleteBookRequest.newBuilder().setName("name3373707").build();
+   *   DeleteBookRequest request =
+   *       DeleteBookRequest.newBuilder()
+   *           .setName(BookName.of("[SHELF]", "[BOOK]").toString())
+   *           .build();
    *   ApiFuture future = libraryServiceClient.deleteBookCallable().futureCall(request);
    *   // Do something.
    *   future.get();
@@ -1038,15 +1095,18 @@ public final UnaryCallable deleteBookCallable() {
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
    *   Book book = Book.newBuilder().build();
-   *   Book response = libraryServiceClient.updateBook(book);
+   *   FieldMask updateMask = FieldMask.newBuilder().build();
+   *   Book response = libraryServiceClient.updateBook(book, updateMask);
    * }
    * }
* - * @param book The book to update with. The name must match or be empty. + * @param book The name of the book to update. + * @param updateMask Required. Mask of fields to update. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - public final Book updateBook(Book book) { - UpdateBookRequest request = UpdateBookRequest.newBuilder().setBook(book).build(); + public final Book updateBook(Book book, FieldMask updateMask) { + UpdateBookRequest request = + UpdateBookRequest.newBuilder().setBook(book).setUpdateMask(updateMask).build(); return updateBook(request); } @@ -1061,8 +1121,8 @@ public final Book updateBook(Book book) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * UpdateBookRequest request = * UpdateBookRequest.newBuilder() - * .setName("name3373707") * .setBook(Book.newBuilder().build()) + * .setUpdateMask(FieldMask.newBuilder().build()) * .build(); * Book response = libraryServiceClient.updateBook(request); * } @@ -1086,8 +1146,8 @@ public final Book updateBook(UpdateBookRequest request) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * UpdateBookRequest request = * UpdateBookRequest.newBuilder() - * .setName("name3373707") * .setBook(Book.newBuilder().build()) + * .setUpdateMask(FieldMask.newBuilder().build()) * .build(); * ApiFuture future = libraryServiceClient.updateBookCallable().futureCall(request); * // Do something. @@ -1108,7 +1168,7 @@ public final UnaryCallable updateBookCallable() { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
+   *   BookName name = BookName.of("[SHELF]", "[BOOK]");
    *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
    *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
    * }
@@ -1136,8 +1196,8 @@ public final Book moveBook(BookName name, ShelfName otherShelfName) {
    *
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]");
-   *   String otherShelfName = "otherShelfName-1942963547";
+   *   BookName name = BookName.of("[SHELF]", "[BOOK]");
+   *   String otherShelfName = ShelfName.of("[SHELF_ID]").toString();
    *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
    * }
    * }
@@ -1164,7 +1224,7 @@ public final Book moveBook(BookName name, String otherShelfName) { * *
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
+   *   String name = BookName.of("[SHELF]", "[BOOK]").toString();
    *   ShelfName otherShelfName = ShelfName.of("[SHELF_ID]");
    *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
    * }
@@ -1192,8 +1252,8 @@ public final Book moveBook(String name, ShelfName otherShelfName) {
    *
    * 
{@code
    * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
-   *   String name = "name3373707";
-   *   String otherShelfName = "otherShelfName-1942963547";
+   *   String name = BookName.of("[SHELF]", "[BOOK]").toString();
+   *   String otherShelfName = ShelfName.of("[SHELF_ID]").toString();
    *   Book response = libraryServiceClient.moveBook(name, otherShelfName);
    * }
    * }
@@ -1219,8 +1279,8 @@ public final Book moveBook(String name, String otherShelfName) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * MoveBookRequest request = * MoveBookRequest.newBuilder() - * .setName("name3373707") - * .setOtherShelfName("otherShelfName-1942963547") + * .setName(BookName.of("[SHELF]", "[BOOK]").toString()) + * .setOtherShelfName(ShelfName.of("[SHELF_ID]").toString()) * .build(); * Book response = libraryServiceClient.moveBook(request); * } @@ -1244,8 +1304,8 @@ public final Book moveBook(MoveBookRequest request) { * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) { * MoveBookRequest request = * MoveBookRequest.newBuilder() - * .setName("name3373707") - * .setOtherShelfName("otherShelfName-1942963547") + * .setName(BookName.of("[SHELF]", "[BOOK]").toString()) + * .setOtherShelfName(ShelfName.of("[SHELF_ID]").toString()) * .build(); * ApiFuture future = libraryServiceClient.moveBookCallable().futureCall(request); * // Do something. diff --git a/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClientTest.java b/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClientTest.java index 59b7b89caa..5cc5819105 100644 --- a/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClientTest.java +++ b/test/integration/goldens/library/com/google/cloud/example/library/v1/LibraryServiceClientTest.java @@ -46,6 +46,7 @@ import com.google.example.library.v1.UpdateBookRequest; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; import io.grpc.StatusRuntimeException; import java.io.IOException; import java.util.Arrays; @@ -345,9 +346,9 @@ public void mergeShelvesTest() throws Exception { mockLibraryService.addResponse(expectedResponse); ShelfName name = ShelfName.of("[SHELF_ID]"); - ShelfName otherShelfName = ShelfName.of("[SHELF_ID]"); + ShelfName otherShelf = ShelfName.of("[SHELF_ID]"); - Shelf actualResponse = client.mergeShelves(name, otherShelfName); + Shelf actualResponse = client.mergeShelves(name, otherShelf); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); @@ -355,7 +356,7 @@ public void mergeShelvesTest() throws Exception { MergeShelvesRequest actualRequest = ((MergeShelvesRequest) actualRequests.get(0)); Assert.assertEquals(name.toString(), actualRequest.getName()); - Assert.assertEquals(otherShelfName.toString(), actualRequest.getOtherShelfName()); + Assert.assertEquals(otherShelf.toString(), actualRequest.getOtherShelf()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -369,8 +370,8 @@ public void mergeShelvesExceptionTest() throws Exception { try { ShelfName name = ShelfName.of("[SHELF_ID]"); - ShelfName otherShelfName = ShelfName.of("[SHELF_ID]"); - client.mergeShelves(name, otherShelfName); + ShelfName otherShelf = ShelfName.of("[SHELF_ID]"); + client.mergeShelves(name, otherShelf); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -387,9 +388,9 @@ public void mergeShelvesTest2() throws Exception { mockLibraryService.addResponse(expectedResponse); ShelfName name = ShelfName.of("[SHELF_ID]"); - String otherShelfName = "otherShelfName-1942963547"; + String otherShelf = "otherShelf-193668870"; - Shelf actualResponse = client.mergeShelves(name, otherShelfName); + Shelf actualResponse = client.mergeShelves(name, otherShelf); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); @@ -397,7 +398,7 @@ public void mergeShelvesTest2() throws Exception { MergeShelvesRequest actualRequest = ((MergeShelvesRequest) actualRequests.get(0)); Assert.assertEquals(name.toString(), actualRequest.getName()); - Assert.assertEquals(otherShelfName, actualRequest.getOtherShelfName()); + Assert.assertEquals(otherShelf, actualRequest.getOtherShelf()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -411,8 +412,8 @@ public void mergeShelvesExceptionTest2() throws Exception { try { ShelfName name = ShelfName.of("[SHELF_ID]"); - String otherShelfName = "otherShelfName-1942963547"; - client.mergeShelves(name, otherShelfName); + String otherShelf = "otherShelf-193668870"; + client.mergeShelves(name, otherShelf); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -429,9 +430,9 @@ public void mergeShelvesTest3() throws Exception { mockLibraryService.addResponse(expectedResponse); String name = "name3373707"; - ShelfName otherShelfName = ShelfName.of("[SHELF_ID]"); + ShelfName otherShelf = ShelfName.of("[SHELF_ID]"); - Shelf actualResponse = client.mergeShelves(name, otherShelfName); + Shelf actualResponse = client.mergeShelves(name, otherShelf); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); @@ -439,7 +440,7 @@ public void mergeShelvesTest3() throws Exception { MergeShelvesRequest actualRequest = ((MergeShelvesRequest) actualRequests.get(0)); Assert.assertEquals(name, actualRequest.getName()); - Assert.assertEquals(otherShelfName.toString(), actualRequest.getOtherShelfName()); + Assert.assertEquals(otherShelf.toString(), actualRequest.getOtherShelf()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -453,8 +454,8 @@ public void mergeShelvesExceptionTest3() throws Exception { try { String name = "name3373707"; - ShelfName otherShelfName = ShelfName.of("[SHELF_ID]"); - client.mergeShelves(name, otherShelfName); + ShelfName otherShelf = ShelfName.of("[SHELF_ID]"); + client.mergeShelves(name, otherShelf); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -471,9 +472,9 @@ public void mergeShelvesTest4() throws Exception { mockLibraryService.addResponse(expectedResponse); String name = "name3373707"; - String otherShelfName = "otherShelfName-1942963547"; + String otherShelf = "otherShelf-193668870"; - Shelf actualResponse = client.mergeShelves(name, otherShelfName); + Shelf actualResponse = client.mergeShelves(name, otherShelf); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); @@ -481,7 +482,7 @@ public void mergeShelvesTest4() throws Exception { MergeShelvesRequest actualRequest = ((MergeShelvesRequest) actualRequests.get(0)); Assert.assertEquals(name, actualRequest.getName()); - Assert.assertEquals(otherShelfName, actualRequest.getOtherShelfName()); + Assert.assertEquals(otherShelf, actualRequest.getOtherShelf()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -495,8 +496,8 @@ public void mergeShelvesExceptionTest4() throws Exception { try { String name = "name3373707"; - String otherShelfName = "otherShelfName-1942963547"; - client.mergeShelves(name, otherShelfName); + String otherShelf = "otherShelf-193668870"; + client.mergeShelves(name, otherShelf); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -507,24 +508,24 @@ public void mergeShelvesExceptionTest4() throws Exception { public void createBookTest() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) .build(); mockLibraryService.addResponse(expectedResponse); - ShelfName name = ShelfName.of("[SHELF_ID]"); + ShelfName parent = ShelfName.of("[SHELF_ID]"); Book book = Book.newBuilder().build(); - Book actualResponse = client.createBook(name, book); + Book actualResponse = client.createBook(parent, book); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateBookRequest actualRequest = ((CreateBookRequest) actualRequests.get(0)); - Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertEquals(parent.toString(), actualRequest.getParent()); Assert.assertEquals(book, actualRequest.getBook()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -538,9 +539,9 @@ public void createBookExceptionTest() throws Exception { mockLibraryService.addException(exception); try { - ShelfName name = ShelfName.of("[SHELF_ID]"); + ShelfName parent = ShelfName.of("[SHELF_ID]"); Book book = Book.newBuilder().build(); - client.createBook(name, book); + client.createBook(parent, book); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -551,24 +552,24 @@ public void createBookExceptionTest() throws Exception { public void createBookTest2() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) .build(); mockLibraryService.addResponse(expectedResponse); - String name = "name3373707"; + String parent = "parent-995424086"; Book book = Book.newBuilder().build(); - Book actualResponse = client.createBook(name, book); + Book actualResponse = client.createBook(parent, book); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateBookRequest actualRequest = ((CreateBookRequest) actualRequests.get(0)); - Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(parent, actualRequest.getParent()); Assert.assertEquals(book, actualRequest.getBook()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -582,9 +583,9 @@ public void createBookExceptionTest2() throws Exception { mockLibraryService.addException(exception); try { - String name = "name3373707"; + String parent = "parent-995424086"; Book book = Book.newBuilder().build(); - client.createBook(name, book); + client.createBook(parent, book); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -595,14 +596,14 @@ public void createBookExceptionTest2() throws Exception { public void getBookTest() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) .build(); mockLibraryService.addResponse(expectedResponse); - BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]"); + BookName name = BookName.of("[SHELF]", "[BOOK]"); Book actualResponse = client.getBook(name); Assert.assertEquals(expectedResponse, actualResponse); @@ -624,7 +625,7 @@ public void getBookExceptionTest() throws Exception { mockLibraryService.addException(exception); try { - BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]"); + BookName name = BookName.of("[SHELF]", "[BOOK]"); client.getBook(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { @@ -636,7 +637,7 @@ public void getBookExceptionTest() throws Exception { public void getBookTest2() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) @@ -683,9 +684,9 @@ public void listBooksTest() throws Exception { .build(); mockLibraryService.addResponse(expectedResponse); - ShelfName name = ShelfName.of("[SHELF_ID]"); + ShelfName parent = ShelfName.of("[SHELF_ID]"); - ListBooksPagedResponse pagedListResponse = client.listBooks(name); + ListBooksPagedResponse pagedListResponse = client.listBooks(parent); List resources = Lists.newArrayList(pagedListResponse.iterateAll()); @@ -696,7 +697,7 @@ public void listBooksTest() throws Exception { Assert.assertEquals(1, actualRequests.size()); ListBooksRequest actualRequest = ((ListBooksRequest) actualRequests.get(0)); - Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertEquals(parent.toString(), actualRequest.getParent()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -709,8 +710,8 @@ public void listBooksExceptionTest() throws Exception { mockLibraryService.addException(exception); try { - ShelfName name = ShelfName.of("[SHELF_ID]"); - client.listBooks(name); + ShelfName parent = ShelfName.of("[SHELF_ID]"); + client.listBooks(parent); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -727,9 +728,9 @@ public void listBooksTest2() throws Exception { .build(); mockLibraryService.addResponse(expectedResponse); - String name = "name3373707"; + String parent = "parent-995424086"; - ListBooksPagedResponse pagedListResponse = client.listBooks(name); + ListBooksPagedResponse pagedListResponse = client.listBooks(parent); List resources = Lists.newArrayList(pagedListResponse.iterateAll()); @@ -740,7 +741,7 @@ public void listBooksTest2() throws Exception { Assert.assertEquals(1, actualRequests.size()); ListBooksRequest actualRequest = ((ListBooksRequest) actualRequests.get(0)); - Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(parent, actualRequest.getParent()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -753,8 +754,8 @@ public void listBooksExceptionTest2() throws Exception { mockLibraryService.addException(exception); try { - String name = "name3373707"; - client.listBooks(name); + String parent = "parent-995424086"; + client.listBooks(parent); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -766,15 +767,15 @@ public void deleteBookTest() throws Exception { Empty expectedResponse = Empty.newBuilder().build(); mockLibraryService.addResponse(expectedResponse); - DeleteBookRequest request = DeleteBookRequest.newBuilder().setName("name3373707").build(); + BookName name = BookName.of("[SHELF]", "[BOOK]"); - client.deleteBook(request); + client.deleteBook(name); List actualRequests = mockLibraryService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteBookRequest actualRequest = ((DeleteBookRequest) actualRequests.get(0)); - Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(name.toString(), actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -787,8 +788,42 @@ public void deleteBookExceptionTest() throws Exception { mockLibraryService.addException(exception); try { - DeleteBookRequest request = DeleteBookRequest.newBuilder().setName("name3373707").build(); - client.deleteBook(request); + BookName name = BookName.of("[SHELF]", "[BOOK]"); + client.deleteBook(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteBookTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockLibraryService.addResponse(expectedResponse); + + String name = "name3373707"; + + client.deleteBook(name); + + List actualRequests = mockLibraryService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteBookRequest actualRequest = ((DeleteBookRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteBookExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLibraryService.addException(exception); + + try { + String name = "name3373707"; + client.deleteBook(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -799,7 +834,7 @@ public void deleteBookExceptionTest() throws Exception { public void updateBookTest() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) @@ -807,8 +842,9 @@ public void updateBookTest() throws Exception { mockLibraryService.addResponse(expectedResponse); Book book = Book.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); - Book actualResponse = client.updateBook(book); + Book actualResponse = client.updateBook(book, updateMask); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockLibraryService.getRequests(); @@ -816,6 +852,7 @@ public void updateBookTest() throws Exception { UpdateBookRequest actualRequest = ((UpdateBookRequest) actualRequests.get(0)); Assert.assertEquals(book, actualRequest.getBook()); + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -829,7 +866,8 @@ public void updateBookExceptionTest() throws Exception { try { Book book = Book.newBuilder().build(); - client.updateBook(book); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateBook(book, updateMask); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception. @@ -840,14 +878,14 @@ public void updateBookExceptionTest() throws Exception { public void moveBookTest() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) .build(); mockLibraryService.addResponse(expectedResponse); - BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]"); + BookName name = BookName.of("[SHELF]", "[BOOK]"); ShelfName otherShelfName = ShelfName.of("[SHELF_ID]"); Book actualResponse = client.moveBook(name, otherShelfName); @@ -871,7 +909,7 @@ public void moveBookExceptionTest() throws Exception { mockLibraryService.addException(exception); try { - BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]"); + BookName name = BookName.of("[SHELF]", "[BOOK]"); ShelfName otherShelfName = ShelfName.of("[SHELF_ID]"); client.moveBook(name, otherShelfName); Assert.fail("No exception raised"); @@ -884,14 +922,14 @@ public void moveBookExceptionTest() throws Exception { public void moveBookTest2() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) .build(); mockLibraryService.addResponse(expectedResponse); - BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]"); + BookName name = BookName.of("[SHELF]", "[BOOK]"); String otherShelfName = "otherShelfName-1942963547"; Book actualResponse = client.moveBook(name, otherShelfName); @@ -915,7 +953,7 @@ public void moveBookExceptionTest2() throws Exception { mockLibraryService.addException(exception); try { - BookName name = BookName.of("[SHELF_ID]", "[BOOK_ID]"); + BookName name = BookName.of("[SHELF]", "[BOOK]"); String otherShelfName = "otherShelfName-1942963547"; client.moveBook(name, otherShelfName); Assert.fail("No exception raised"); @@ -928,7 +966,7 @@ public void moveBookExceptionTest2() throws Exception { public void moveBookTest3() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) @@ -972,7 +1010,7 @@ public void moveBookExceptionTest3() throws Exception { public void moveBookTest4() throws Exception { Book expectedResponse = Book.newBuilder() - .setName(BookName.of("[SHELF_ID]", "[BOOK_ID]").toString()) + .setName(BookName.of("[SHELF]", "[BOOK]").toString()) .setAuthor("author-1406328437") .setTitle("title110371416") .setRead(true) diff --git a/test/integration/goldens/library/com/google/cloud/example/library/v1/gapic_metadata.json b/test/integration/goldens/library/com/google/cloud/example/library/v1/gapic_metadata.json index 412c5f19c7..b2812fef26 100644 --- a/test/integration/goldens/library/com/google/cloud/example/library/v1/gapic_metadata.json +++ b/test/integration/goldens/library/com/google/cloud/example/library/v1/gapic_metadata.json @@ -17,7 +17,7 @@ "methods": ["createShelf", "createShelf", "createShelfCallable"] }, "DeleteBook": { - "methods": ["deleteBook", "deleteBookCallable"] + "methods": ["deleteBook", "deleteBook", "deleteBook", "deleteBookCallable"] }, "DeleteShelf": { "methods": ["deleteShelf", "deleteShelf", "deleteShelf", "deleteShelfCallable"] diff --git a/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java b/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java index 3e09a011a6..c912a9b7b3 100644 --- a/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java +++ b/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java @@ -264,7 +264,7 @@ public Map extract(MergeShelvesRequest request) { @Override public Map extract(CreateBookRequest request) { ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); + params.put("parent", String.valueOf(request.getParent())); return params.build(); } }) @@ -290,7 +290,7 @@ public Map extract(GetBookRequest request) { @Override public Map extract(ListBooksRequest request) { ImmutableMap.Builder params = ImmutableMap.builder(); - params.put("name", String.valueOf(request.getName())); + params.put("parent", String.valueOf(request.getParent())); return params.build(); } }) diff --git a/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/LibraryServiceStubSettings.java b/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/LibraryServiceStubSettings.java index 056516530c..bb98270faa 100644 --- a/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/LibraryServiceStubSettings.java +++ b/test/integration/goldens/library/com/google/cloud/example/library/v1/stub/LibraryServiceStubSettings.java @@ -64,6 +64,7 @@ import java.io.IOException; import java.util.List; import javax.annotation.Generated; +import org.threeten.bp.Duration; // AUTO-GENERATED DOCUMENTATION AND CLASS. /** @@ -392,7 +393,13 @@ public static class Builder extends StubSettings.Builder> definitions = ImmutableMap.builder(); - definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_1_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_0_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -401,8 +408,28 @@ public static class Builder extends StubSettings.Builder definitions = ImmutableMap.builder(); RetrySettings settings = null; - settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); - definitions.put("no_retry_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(60000L)) + .setTotalTimeout(Duration.ofMillis(60000L)) + .build(); + definitions.put("retry_policy_1_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(60000L)) + .setTotalTimeout(Duration.ofMillis(60000L)) + .build(); + definitions.put("retry_policy_0_params", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); } @@ -487,58 +514,58 @@ private static Builder createDefault() { private static Builder initDefaults(Builder builder) { builder .createShelfSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); builder .getShelfSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .listShelvesSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .deleteShelfSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .mergeShelvesSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); builder .createBookSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); builder .getBookSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .listBooksSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .deleteBookSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .updateBookSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .moveBookSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); return builder; } diff --git a/test/integration/goldens/library/com/google/example/library/v1/BookName.java b/test/integration/goldens/library/com/google/example/library/v1/BookName.java index a79c744949..d329e387f0 100644 --- a/test/integration/goldens/library/com/google/example/library/v1/BookName.java +++ b/test/integration/goldens/library/com/google/example/library/v1/BookName.java @@ -29,29 +29,29 @@ // AUTO-GENERATED DOCUMENTATION AND CLASS. @Generated("by gapic-generator-java") public class BookName implements ResourceName { - private static final PathTemplate SHELF_ID_BOOK_ID = - PathTemplate.createWithoutUrlEncoding("shelves/{shelf_id}/books/{book_id}"); + private static final PathTemplate SHELF_BOOK = + PathTemplate.createWithoutUrlEncoding("shelves/{shelf}/books/{book}"); private volatile Map fieldValuesMap; - private final String shelfId; - private final String bookId; + private final String shelf; + private final String book; @Deprecated protected BookName() { - shelfId = null; - bookId = null; + shelf = null; + book = null; } private BookName(Builder builder) { - shelfId = Preconditions.checkNotNull(builder.getShelfId()); - bookId = Preconditions.checkNotNull(builder.getBookId()); + shelf = Preconditions.checkNotNull(builder.getShelf()); + book = Preconditions.checkNotNull(builder.getBook()); } - public String getShelfId() { - return shelfId; + public String getShelf() { + return shelf; } - public String getBookId() { - return bookId; + public String getBook() { + return book; } public static Builder newBuilder() { @@ -62,12 +62,12 @@ public Builder toBuilder() { return new Builder(this); } - public static BookName of(String shelfId, String bookId) { - return newBuilder().setShelfId(shelfId).setBookId(bookId).build(); + public static BookName of(String shelf, String book) { + return newBuilder().setShelf(shelf).setBook(book).build(); } - public static String format(String shelfId, String bookId) { - return newBuilder().setShelfId(shelfId).setBookId(bookId).build().toString(); + public static String format(String shelf, String book) { + return newBuilder().setShelf(shelf).setBook(book).build().toString(); } public static BookName parse(String formattedString) { @@ -75,9 +75,9 @@ public static BookName parse(String formattedString) { return null; } Map matchMap = - SHELF_ID_BOOK_ID.validatedMatch( + SHELF_BOOK.validatedMatch( formattedString, "BookName.parse: formattedString not in valid format"); - return of(matchMap.get("shelf_id"), matchMap.get("book_id")); + return of(matchMap.get("shelf"), matchMap.get("book")); } public static List parseList(List formattedStrings) { @@ -101,7 +101,7 @@ public static List toStringList(List values) { } public static boolean isParsableFrom(String formattedString) { - return SHELF_ID_BOOK_ID.matches(formattedString); + return SHELF_BOOK.matches(formattedString); } @Override @@ -110,11 +110,11 @@ public Map getFieldValuesMap() { synchronized (this) { if (fieldValuesMap == null) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - if (shelfId != null) { - fieldMapBuilder.put("shelf_id", shelfId); + if (shelf != null) { + fieldMapBuilder.put("shelf", shelf); } - if (bookId != null) { - fieldMapBuilder.put("book_id", bookId); + if (book != null) { + fieldMapBuilder.put("book", book); } fieldValuesMap = fieldMapBuilder.build(); } @@ -129,7 +129,7 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return SHELF_ID_BOOK_ID.instantiate("shelf_id", shelfId, "book_id", bookId); + return SHELF_BOOK.instantiate("shelf", shelf, "book", book); } @Override @@ -139,7 +139,7 @@ public boolean equals(Object o) { } if (o != null || getClass() == o.getClass()) { BookName that = ((BookName) o); - return Objects.equals(this.shelfId, that.shelfId) && Objects.equals(this.bookId, that.bookId); + return Objects.equals(this.shelf, that.shelf) && Objects.equals(this.book, that.book); } return false; } @@ -148,40 +148,40 @@ public boolean equals(Object o) { public int hashCode() { int h = 1; h *= 1000003; - h ^= Objects.hashCode(shelfId); + h ^= Objects.hashCode(shelf); h *= 1000003; - h ^= Objects.hashCode(bookId); + h ^= Objects.hashCode(book); return h; } - /** Builder for shelves/{shelf_id}/books/{book_id}. */ + /** Builder for shelves/{shelf}/books/{book}. */ public static class Builder { - private String shelfId; - private String bookId; + private String shelf; + private String book; protected Builder() {} - public String getShelfId() { - return shelfId; + public String getShelf() { + return shelf; } - public String getBookId() { - return bookId; + public String getBook() { + return book; } - public Builder setShelfId(String shelfId) { - this.shelfId = shelfId; + public Builder setShelf(String shelf) { + this.shelf = shelf; return this; } - public Builder setBookId(String bookId) { - this.bookId = bookId; + public Builder setBook(String book) { + this.book = book; return this; } private Builder(BookName bookName) { - shelfId = bookName.shelfId; - bookId = bookName.bookId; + shelf = bookName.shelf; + book = bookName.book; } public BookName build() { diff --git a/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/SchemaServiceClient.java b/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/SchemaServiceClient.java index 66ecc5c548..f7b5f91ffe 100644 --- a/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/SchemaServiceClient.java +++ b/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/SchemaServiceClient.java @@ -54,8 +54,10 @@ // AUTO-GENERATED DOCUMENTATION AND CLASS. /** - * This class provides the ability to make remote calls to the backing service through method calls - * that map to API methods. Sample code to get started: + * Service Description: Service for doing schema-related operations. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: * *

{@code
  * try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
diff --git a/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/package-info.java b/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/package-info.java
index 776d93208b..128d542475 100644
--- a/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/package-info.java
+++ b/test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/package-info.java
@@ -54,6 +54,8 @@
  *
  * 

======================= SchemaServiceClient ======================= * + *

Service Description: Service for doing schema-related operations. + * *

Sample for SchemaServiceClient: * *

{@code