From d33d68d367dabc4d8e58aa78d30f238dcd26ddf6 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 27 Jun 2022 18:48:11 +0000 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#670) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 --- google-cloud-billing/pom.xml | 16 + .../cloud/billing/v1/CloudBillingClient.java | 14 + .../billing/v1/CloudBillingSettings.java | 23 +- .../cloud/billing/v1/CloudCatalogClient.java | 14 + .../billing/v1/CloudCatalogSettings.java | 23 +- .../v1/stub/CloudBillingStubSettings.java | 53 +- .../v1/stub/CloudCatalogStubSettings.java | 53 +- .../HttpJsonCloudBillingCallableFactory.java | 105 +++ .../v1/stub/HttpJsonCloudBillingStub.java | 725 +++++++++++++++ .../HttpJsonCloudCatalogCallableFactory.java | 105 +++ .../v1/stub/HttpJsonCloudCatalogStub.java | 270 ++++++ .../v1/CloudBillingClientHttpJsonTest.java | 853 ++++++++++++++++++ .../v1/CloudCatalogClientHttpJsonTest.java | 230 +++++ .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../AsyncCreateBillingAccount.java | 46 + .../SyncCreateBillingAccount.java | 42 + ...yncCreateBillingAccountBillingaccount.java | 38 + .../AsyncGetBillingAccount.java | 47 + .../SyncGetBillingAccount.java | 43 + ...ncGetBillingAccountBillingaccountname.java | 39 + .../SyncGetBillingAccountString.java | 39 + .../getiampolicy/AsyncGetIamPolicy.java | 48 + .../getiampolicy/SyncGetIamPolicy.java | 45 + .../SyncGetIamPolicyResourcename.java | 40 + .../getiampolicy/SyncGetIamPolicyString.java | 39 + .../AsyncGetProjectBillingInfo.java | 44 + .../SyncGetProjectBillingInfo.java | 40 + .../SyncGetProjectBillingInfoString.java | 38 + .../AsyncListBillingAccounts.java | 50 + .../AsyncListBillingAccountsPaged.java | 58 ++ .../SyncListBillingAccounts.java | 46 + .../SyncListBillingAccountsNoargs.java | 39 + .../AsyncListProjectBillingInfo.java | 51 ++ .../AsyncListProjectBillingInfoPaged.java | 59 ++ .../SyncListProjectBillingInfo.java | 48 + ...tProjectBillingInfoBillingaccountname.java | 42 + .../SyncListProjectBillingInfoString.java | 42 + .../setiampolicy/AsyncSetIamPolicy.java | 49 + .../setiampolicy/SyncSetIamPolicy.java | 46 + .../SyncSetIamPolicyResourcenamePolicy.java | 41 + .../SyncSetIamPolicyStringPolicy.java | 40 + .../AsyncTestIamPermissions.java | 49 + .../SyncTestIamPermissions.java | 45 + ...tIamPermissionsResourcenameListstring.java | 44 + ...yncTestIamPermissionsStringListstring.java | 43 + .../AsyncUpdateBillingAccount.java | 50 + .../SyncUpdateBillingAccount.java | 46 + ...countBillingaccountnameBillingaccount.java | 42 + ...ateBillingAccountStringBillingaccount.java | 40 + .../AsyncUpdateProjectBillingInfo.java | 47 + .../SyncUpdateProjectBillingInfo.java | 43 + ...ctBillingInfoStringProjectbillinginfo.java | 42 + .../SyncGetBillingAccount.java | 45 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../listservices/AsyncListServices.java | 49 + .../listservices/AsyncListServicesPaged.java | 56 ++ .../listservices/SyncListServices.java | 45 + .../listservices/SyncListServicesNoargs.java | 39 + .../listskus/AsyncListSkus.java | 54 ++ .../listskus/AsyncListSkusPaged.java | 62 ++ .../listskus/SyncListSkus.java | 51 ++ .../listskus/SyncListSkusServicename.java | 41 + .../listskus/SyncListSkusString.java | 41 + .../listservices/SyncListServices.java | 45 + .../SyncGetBillingAccount.java | 46 + .../listservices/SyncListServices.java | 46 + 70 files changed, 5022 insertions(+), 10 deletions(-) create mode 100644 google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingCallableFactory.java create mode 100644 google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingStub.java create mode 100644 google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogCallableFactory.java create mode 100644 google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogStub.java create mode 100644 google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudBillingClientHttpJsonTest.java create mode 100644 google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudCatalogClientHttpJsonTest.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/AsyncCreateBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccountBillingaccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/AsyncGetBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountBillingaccountname.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountString.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/AsyncGetIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyResourcename.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyString.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/AsyncGetProjectBillingInfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfoString.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccounts.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccountsPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccounts.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccountsNoargs.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfoPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoBillingaccountname.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoString.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/AsyncSetIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyResourcenamePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyStringPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/AsyncTestIamPermissions.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissions.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsResourcenameListstring.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsStringListstring.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/AsyncUpdateBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountBillingaccountnameBillingaccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountStringBillingaccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/AsyncUpdateProjectBillingInfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfoStringProjectbillinginfo.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingsettings/getbillingaccount/SyncGetBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServices.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServicesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServices.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServicesNoargs.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkus.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkusPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkus.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusServicename.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusString.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogsettings/listservices/SyncListServices.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudbillingstubsettings/getbillingaccount/SyncGetBillingAccount.java create mode 100644 samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudcatalogstubsettings/listservices/SyncListServices.java diff --git a/google-cloud-billing/pom.xml b/google-cloud-billing/pom.xml index 8d61c3cd..af1369e4 100644 --- a/google-cloud-billing/pom.xml +++ b/google-cloud-billing/pom.xml @@ -61,6 +61,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -78,12 +82,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingClient.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingClient.java index edd9f2a2..6ffa5640 100644 --- a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingClient.java +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingClient.java @@ -102,6 +102,20 @@ * CloudBillingClient cloudBillingClient = CloudBillingClient.create(cloudBillingSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * CloudBillingSettings cloudBillingSettings =
+ *     CloudBillingSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudBillingSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudBillingClient cloudBillingClient = CloudBillingClient.create(cloudBillingSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingSettings.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingSettings.java index 5f88c74a..a7a396c5 100644 --- a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingSettings.java +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingSettings.java @@ -24,6 +24,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -162,11 +163,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudBillingStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return CloudBillingStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudBillingStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudBillingStubSettings.defaultTransportChannelProvider(); } @@ -176,11 +184,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudBillingStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -218,6 +232,11 @@ private static Builder createDefault() { return new Builder(CloudBillingStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudBillingStubSettings.newHttpJsonBuilder()); + } + public CloudBillingStubSettings.Builder getStubSettingsBuilder() { return ((CloudBillingStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogClient.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogClient.java index 76d36bfa..4b55ed5a 100644 --- a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogClient.java +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogClient.java @@ -98,6 +98,20 @@ * CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create(cloudCatalogSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * CloudCatalogSettings cloudCatalogSettings =
+ *     CloudCatalogSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CloudCatalogSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create(cloudCatalogSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogSettings.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogSettings.java index f24dc378..3c1a4954 100644 --- a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogSettings.java +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudCatalogSettings.java @@ -24,6 +24,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -108,11 +109,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CloudCatalogStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return CloudCatalogStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CloudCatalogStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CloudCatalogStubSettings.defaultTransportChannelProvider(); } @@ -122,11 +130,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CloudCatalogStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -164,6 +178,11 @@ private static Builder createDefault() { return new Builder(CloudCatalogStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CloudCatalogStubSettings.newHttpJsonBuilder()); + } + public CloudCatalogStubSettings.Builder getStubSettingsBuilder() { return ((CloudCatalogStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudBillingStubSettings.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudBillingStubSettings.java index 90f5923f..44907506 100644 --- a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudBillingStubSettings.java +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudBillingStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -327,6 +330,11 @@ public CloudBillingStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudBillingStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudBillingStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -359,18 +367,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(CloudBillingStubSettings.class)) @@ -378,11 +393,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(CloudBillingStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudBillingStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -554,6 +588,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .getBillingAccountSettings() diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudCatalogStubSettings.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudCatalogStubSettings.java index 73489b8b..6e950afd 100644 --- a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudCatalogStubSettings.java +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/CloudCatalogStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -225,6 +228,11 @@ public CloudCatalogStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudCatalogStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCloudCatalogStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -257,18 +265,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(CloudCatalogStubSettings.class)) @@ -276,11 +291,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(CloudCatalogStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudCatalogStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -372,6 +406,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listServicesSettings() diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingCallableFactory.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingCallableFactory.java new file mode 100644 index 00000000..894f58f0 --- /dev/null +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the CloudBilling service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudBillingCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingStub.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingStub.java new file mode 100644 index 00000000..2ef1b9ac --- /dev/null +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudBillingStub.java @@ -0,0 +1,725 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.stub; + +import static com.google.cloud.billing.v1.CloudBillingClient.ListBillingAccountsPagedResponse; +import static com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CreateBillingAccountRequest; +import com.google.cloud.billing.v1.GetBillingAccountRequest; +import com.google.cloud.billing.v1.GetProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ListBillingAccountsRequest; +import com.google.cloud.billing.v1.ListBillingAccountsResponse; +import com.google.cloud.billing.v1.ListProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ListProjectBillingInfoResponse; +import com.google.cloud.billing.v1.ProjectBillingInfo; +import com.google.cloud.billing.v1.UpdateBillingAccountRequest; +import com.google.cloud.billing.v1.UpdateProjectBillingInfoRequest; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the CloudBilling service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudBillingStub extends CloudBillingStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + getBillingAccountMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/GetBillingAccount") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=billingAccounts/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BillingAccount.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listBillingAccountsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/ListBillingAccounts") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/billingAccounts", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListBillingAccountsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateBillingAccountMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/UpdateBillingAccount") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=billingAccounts/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("account", request.getAccount())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BillingAccount.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createBillingAccountMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/CreateBillingAccount") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/billingAccounts", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("billingAccount", request.getBillingAccount())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BillingAccount.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListProjectBillingInfoRequest, ListProjectBillingInfoResponse> + listProjectBillingInfoMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/ListProjectBillingInfo") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=billingAccounts/*}/projects", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListProjectBillingInfoResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getProjectBillingInfoMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/GetProjectBillingInfo") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*}/billingInfo", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ProjectBillingInfo.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateProjectBillingInfoMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/UpdateProjectBillingInfo") + .setHttpMethod("PUT") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=projects/*}/billingInfo", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("projectBillingInfo", request.getProjectBillingInfo())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ProjectBillingInfo.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=billingAccounts/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "options", request.getOptions()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=billingAccounts/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudBilling/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=billingAccounts/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable getBillingAccountCallable; + private final UnaryCallable + listBillingAccountsCallable; + private final UnaryCallable + listBillingAccountsPagedCallable; + private final UnaryCallable + updateBillingAccountCallable; + private final UnaryCallable + createBillingAccountCallable; + private final UnaryCallable + listProjectBillingInfoCallable; + private final UnaryCallable + listProjectBillingInfoPagedCallable; + private final UnaryCallable + getProjectBillingInfoCallable; + private final UnaryCallable + updateProjectBillingInfoCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudBillingStub create(CloudBillingStubSettings settings) + throws IOException { + return new HttpJsonCloudBillingStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudBillingStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudBillingStub( + CloudBillingStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudBillingStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudBillingStub( + CloudBillingStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudBillingStub, 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 HttpJsonCloudBillingStub(CloudBillingStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudBillingCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudBillingStub, 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 HttpJsonCloudBillingStub( + CloudBillingStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + getBillingAccountTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getBillingAccountMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listBillingAccountsTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listBillingAccountsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateBillingAccountTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateBillingAccountMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + createBillingAccountTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createBillingAccountMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listProjectBillingInfoTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(listProjectBillingInfoMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getProjectBillingInfoTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getProjectBillingInfoMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + updateProjectBillingInfoTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateProjectBillingInfoMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.getBillingAccountCallable = + callableFactory.createUnaryCallable( + getBillingAccountTransportSettings, + settings.getBillingAccountSettings(), + clientContext); + this.listBillingAccountsCallable = + callableFactory.createUnaryCallable( + listBillingAccountsTransportSettings, + settings.listBillingAccountsSettings(), + clientContext); + this.listBillingAccountsPagedCallable = + callableFactory.createPagedCallable( + listBillingAccountsTransportSettings, + settings.listBillingAccountsSettings(), + clientContext); + this.updateBillingAccountCallable = + callableFactory.createUnaryCallable( + updateBillingAccountTransportSettings, + settings.updateBillingAccountSettings(), + clientContext); + this.createBillingAccountCallable = + callableFactory.createUnaryCallable( + createBillingAccountTransportSettings, + settings.createBillingAccountSettings(), + clientContext); + this.listProjectBillingInfoCallable = + callableFactory.createUnaryCallable( + listProjectBillingInfoTransportSettings, + settings.listProjectBillingInfoSettings(), + clientContext); + this.listProjectBillingInfoPagedCallable = + callableFactory.createPagedCallable( + listProjectBillingInfoTransportSettings, + settings.listProjectBillingInfoSettings(), + clientContext); + this.getProjectBillingInfoCallable = + callableFactory.createUnaryCallable( + getProjectBillingInfoTransportSettings, + settings.getProjectBillingInfoSettings(), + clientContext); + this.updateProjectBillingInfoCallable = + callableFactory.createUnaryCallable( + updateProjectBillingInfoTransportSettings, + settings.updateProjectBillingInfoSettings(), + clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(getBillingAccountMethodDescriptor); + methodDescriptors.add(listBillingAccountsMethodDescriptor); + methodDescriptors.add(updateBillingAccountMethodDescriptor); + methodDescriptors.add(createBillingAccountMethodDescriptor); + methodDescriptors.add(listProjectBillingInfoMethodDescriptor); + methodDescriptors.add(getProjectBillingInfoMethodDescriptor); + methodDescriptors.add(updateProjectBillingInfoMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable getBillingAccountCallable() { + return getBillingAccountCallable; + } + + @Override + public UnaryCallable + listBillingAccountsCallable() { + return listBillingAccountsCallable; + } + + @Override + public UnaryCallable + listBillingAccountsPagedCallable() { + return listBillingAccountsPagedCallable; + } + + @Override + public UnaryCallable updateBillingAccountCallable() { + return updateBillingAccountCallable; + } + + @Override + public UnaryCallable createBillingAccountCallable() { + return createBillingAccountCallable; + } + + @Override + public UnaryCallable + listProjectBillingInfoCallable() { + return listProjectBillingInfoCallable; + } + + @Override + public UnaryCallable + listProjectBillingInfoPagedCallable() { + return listProjectBillingInfoPagedCallable; + } + + @Override + public UnaryCallable + getProjectBillingInfoCallable() { + return getProjectBillingInfoCallable; + } + + @Override + public UnaryCallable + updateProjectBillingInfoCallable() { + return updateProjectBillingInfoCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogCallableFactory.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogCallableFactory.java new file mode 100644 index 00000000..6fd3a5af --- /dev/null +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the CloudCatalog service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudCatalogCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogStub.java b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogStub.java new file mode 100644 index 00000000..18d77855 --- /dev/null +++ b/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/stub/HttpJsonCloudCatalogStub.java @@ -0,0 +1,270 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.stub; + +import static com.google.cloud.billing.v1.CloudCatalogClient.ListServicesPagedResponse; +import static com.google.cloud.billing.v1.CloudCatalogClient.ListSkusPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.billing.v1.ListServicesRequest; +import com.google.cloud.billing.v1.ListServicesResponse; +import com.google.cloud.billing.v1.ListSkusRequest; +import com.google.cloud.billing.v1.ListSkusResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the CloudCatalog service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonCloudCatalogStub extends CloudCatalogStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listServicesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudCatalog/ListServices") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/services", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListServicesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listSkusMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.billing.v1.CloudCatalog/ListSkus") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=services/*}/skus", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "currencyCode", request.getCurrencyCode()); + serializer.putQueryParam(fields, "endTime", request.getEndTime()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "startTime", request.getStartTime()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListSkusResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listServicesCallable; + private final UnaryCallable + listServicesPagedCallable; + private final UnaryCallable listSkusCallable; + private final UnaryCallable listSkusPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCloudCatalogStub create(CloudCatalogStubSettings settings) + throws IOException { + return new HttpJsonCloudCatalogStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCloudCatalogStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCloudCatalogStub( + CloudCatalogStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCloudCatalogStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCloudCatalogStub( + CloudCatalogStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCloudCatalogStub, 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 HttpJsonCloudCatalogStub(CloudCatalogStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonCloudCatalogCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCloudCatalogStub, 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 HttpJsonCloudCatalogStub( + CloudCatalogStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listServicesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listServicesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listSkusTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listSkusMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listServicesCallable = + callableFactory.createUnaryCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.listServicesPagedCallable = + callableFactory.createPagedCallable( + listServicesTransportSettings, settings.listServicesSettings(), clientContext); + this.listSkusCallable = + callableFactory.createUnaryCallable( + listSkusTransportSettings, settings.listSkusSettings(), clientContext); + this.listSkusPagedCallable = + callableFactory.createPagedCallable( + listSkusTransportSettings, settings.listSkusSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listServicesMethodDescriptor); + methodDescriptors.add(listSkusMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listServicesCallable() { + return listServicesCallable; + } + + @Override + public UnaryCallable listServicesPagedCallable() { + return listServicesPagedCallable; + } + + @Override + public UnaryCallable listSkusCallable() { + return listSkusCallable; + } + + @Override + public UnaryCallable listSkusPagedCallable() { + return listSkusPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudBillingClientHttpJsonTest.java b/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudBillingClientHttpJsonTest.java new file mode 100644 index 00000000..ba9f3b92 --- /dev/null +++ b/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudBillingClientHttpJsonTest.java @@ -0,0 +1,853 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1; + +import static com.google.cloud.billing.v1.CloudBillingClient.ListBillingAccountsPagedResponse; +import static com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.billing.v1.stub.HttpJsonCloudBillingStub; +import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.Policy; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.ByteString; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudBillingClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudBillingClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudBillingStub.getMethodDescriptors(), + CloudBillingSettings.getDefaultEndpoint()); + CloudBillingSettings settings = + CloudBillingSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudBillingSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudBillingClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void getBillingAccountTest() throws Exception { + BillingAccount expectedResponse = + BillingAccount.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOpen(true) + .setDisplayName("displayName1714148973") + .setMasterBillingAccount("masterBillingAccount1488941620") + .build(); + mockService.addResponse(expectedResponse); + + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + + BillingAccount actualResponse = client.getBillingAccount(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBillingAccountExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + client.getBillingAccount(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBillingAccountTest2() throws Exception { + BillingAccount expectedResponse = + BillingAccount.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOpen(true) + .setDisplayName("displayName1714148973") + .setMasterBillingAccount("masterBillingAccount1488941620") + .build(); + mockService.addResponse(expectedResponse); + + String name = "billingAccounts/billingAccount-6593"; + + BillingAccount actualResponse = client.getBillingAccount(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getBillingAccountExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "billingAccounts/billingAccount-6593"; + client.getBillingAccount(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBillingAccountsTest() throws Exception { + BillingAccount responsesElement = BillingAccount.newBuilder().build(); + ListBillingAccountsResponse expectedResponse = + ListBillingAccountsResponse.newBuilder() + .setNextPageToken("") + .addAllBillingAccounts(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListBillingAccountsPagedResponse pagedListResponse = client.listBillingAccounts(); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBillingAccountsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listBillingAccountsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListBillingAccountsRequest request = + ListBillingAccountsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + client.listBillingAccounts(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBillingAccountTest() throws Exception { + BillingAccount expectedResponse = + BillingAccount.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOpen(true) + .setDisplayName("displayName1714148973") + .setMasterBillingAccount("masterBillingAccount1488941620") + .build(); + mockService.addResponse(expectedResponse); + + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + BillingAccount account = BillingAccount.newBuilder().build(); + + BillingAccount actualResponse = client.updateBillingAccount(name, account); + 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 updateBillingAccountExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + BillingAccount account = BillingAccount.newBuilder().build(); + client.updateBillingAccount(name, account); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBillingAccountTest2() throws Exception { + BillingAccount expectedResponse = + BillingAccount.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOpen(true) + .setDisplayName("displayName1714148973") + .setMasterBillingAccount("masterBillingAccount1488941620") + .build(); + mockService.addResponse(expectedResponse); + + String name = "billingAccounts/billingAccount-6593"; + BillingAccount account = BillingAccount.newBuilder().build(); + + BillingAccount actualResponse = client.updateBillingAccount(name, account); + 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 updateBillingAccountExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "billingAccounts/billingAccount-6593"; + BillingAccount account = BillingAccount.newBuilder().build(); + client.updateBillingAccount(name, account); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createBillingAccountTest() throws Exception { + BillingAccount expectedResponse = + BillingAccount.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOpen(true) + .setDisplayName("displayName1714148973") + .setMasterBillingAccount("masterBillingAccount1488941620") + .build(); + mockService.addResponse(expectedResponse); + + BillingAccount billingAccount = BillingAccount.newBuilder().build(); + + BillingAccount actualResponse = client.createBillingAccount(billingAccount); + 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 createBillingAccountExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BillingAccount billingAccount = BillingAccount.newBuilder().build(); + client.createBillingAccount(billingAccount); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listProjectBillingInfoTest() throws Exception { + ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build(); + ListProjectBillingInfoResponse expectedResponse = + ListProjectBillingInfoResponse.newBuilder() + .setNextPageToken("") + .addAllProjectBillingInfo(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + + ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listProjectBillingInfoExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + client.listProjectBillingInfo(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listProjectBillingInfoTest2() throws Exception { + ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build(); + ListProjectBillingInfoResponse expectedResponse = + ListProjectBillingInfoResponse.newBuilder() + .setNextPageToken("") + .addAllProjectBillingInfo(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String name = "billingAccounts/billingAccount-6593"; + + ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listProjectBillingInfoExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "billingAccounts/billingAccount-6593"; + client.listProjectBillingInfo(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getProjectBillingInfoTest() throws Exception { + ProjectBillingInfo expectedResponse = + ProjectBillingInfo.newBuilder() + .setName("name3373707") + .setProjectId("projectId-894832108") + .setBillingAccountName("billingAccountName929322205") + .setBillingEnabled(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3664"; + + ProjectBillingInfo actualResponse = client.getProjectBillingInfo(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getProjectBillingInfoExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3664"; + client.getProjectBillingInfo(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateProjectBillingInfoTest() throws Exception { + ProjectBillingInfo expectedResponse = + ProjectBillingInfo.newBuilder() + .setName("name3373707") + .setProjectId("projectId-894832108") + .setBillingAccountName("billingAccountName929322205") + .setBillingEnabled(true) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3664"; + ProjectBillingInfo projectBillingInfo = ProjectBillingInfo.newBuilder().build(); + + ProjectBillingInfo actualResponse = client.updateProjectBillingInfo(name, projectBillingInfo); + 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 updateProjectBillingInfoExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3664"; + ProjectBillingInfo projectBillingInfo = ProjectBillingInfo.newBuilder().build(); + client.updateProjectBillingInfo(name, projectBillingInfo); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + + Policy actualResponse = client.getIamPolicy(resource); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "billingAccounts/billingAccount-2850"; + + Policy actualResponse = client.getIamPolicy(resource); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "billingAccounts/billingAccount-2850"; + client.getIamPolicy(resource); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void setIamPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + String resource = "billingAccounts/billingAccount-2850"; + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.setIamPolicy(resource, policy); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "billingAccounts/billingAccount-2850"; + Policy policy = Policy.newBuilder().build(); + client.setIamPolicy(resource, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest2() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String resource = "billingAccounts/billingAccount-2850"; + List permissions = new ArrayList<>(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String resource = "billingAccounts/billingAccount-2850"; + List permissions = new ArrayList<>(); + client.testIamPermissions(resource, permissions); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudCatalogClientHttpJsonTest.java b/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudCatalogClientHttpJsonTest.java new file mode 100644 index 00000000..4306f71f --- /dev/null +++ b/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudCatalogClientHttpJsonTest.java @@ -0,0 +1,230 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1; + +import static com.google.cloud.billing.v1.CloudCatalogClient.ListServicesPagedResponse; +import static com.google.cloud.billing.v1.CloudCatalogClient.ListSkusPagedResponse; + +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.billing.v1.stub.HttpJsonCloudCatalogStub; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudCatalogClientHttpJsonTest { + private static MockHttpService mockService; + private static CloudCatalogClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCloudCatalogStub.getMethodDescriptors(), + CloudCatalogSettings.getDefaultEndpoint()); + CloudCatalogSettings settings = + CloudCatalogSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CloudCatalogSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudCatalogClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listServicesTest() throws Exception { + Service responsesElement = Service.newBuilder().build(); + ListServicesResponse expectedResponse = + ListServicesResponse.newBuilder() + .setNextPageToken("") + .addAllServices(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListServicesPagedResponse pagedListResponse = client.listServices(); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listServicesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listServices(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSkusTest() throws Exception { + Sku responsesElement = Sku.newBuilder().build(); + ListSkusResponse expectedResponse = + ListSkusResponse.newBuilder() + .setNextPageToken("") + .addAllSkus(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ServiceName parent = ServiceName.of("[SERVICE]"); + + ListSkusPagedResponse pagedListResponse = client.listSkus(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSkusList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSkusExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ServiceName parent = ServiceName.of("[SERVICE]"); + client.listSkus(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSkusTest2() throws Exception { + Sku responsesElement = Sku.newBuilder().build(); + ListSkusResponse expectedResponse = + ListSkusResponse.newBuilder() + .setNextPageToken("") + .addAllSkus(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "services/service-5597"; + + ListSkusPagedResponse pagedListResponse = client.listSkus(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSkusList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSkusExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "services/service-5597"; + client.listSkus(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..0b9e17dd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.CloudBillingSettings; +import com.google.cloud.billing.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudBillingSettings cloudBillingSettings = + CloudBillingSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudBillingClient cloudBillingClient = CloudBillingClient.create(cloudBillingSettings); + } +} +// [END billing_v1_generated_cloudbillingclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..91ce03d5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_create_setcredentialsprovider1_sync] +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.CloudBillingSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudBillingSettings cloudBillingSettings = + CloudBillingSettings.newBuilder() + .setTransportChannelProvider( + CloudBillingSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudBillingClient cloudBillingClient = CloudBillingClient.create(cloudBillingSettings); + } +} +// [END billing_v1_generated_cloudbillingclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..6fb2ad34 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_create_setendpoint_sync] +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.CloudBillingSettings; +import com.google.cloud.billing.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudBillingSettings cloudBillingSettings = + CloudBillingSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudBillingClient cloudBillingClient = CloudBillingClient.create(cloudBillingSettings); + } +} +// [END billing_v1_generated_cloudbillingclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/AsyncCreateBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/AsyncCreateBillingAccount.java new file mode 100644 index 00000000..d2a11bb6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/AsyncCreateBillingAccount.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_createbillingaccount_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.CreateBillingAccountRequest; + +public class AsyncCreateBillingAccount { + + public static void main(String[] args) throws Exception { + asyncCreateBillingAccount(); + } + + public static void asyncCreateBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + CreateBillingAccountRequest request = + CreateBillingAccountRequest.newBuilder() + .setBillingAccount(BillingAccount.newBuilder().build()) + .build(); + ApiFuture future = + cloudBillingClient.createBillingAccountCallable().futureCall(request); + // Do something. + BillingAccount response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_createbillingaccount_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccount.java new file mode 100644 index 00000000..809869c3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccount.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_createbillingaccount_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.CreateBillingAccountRequest; + +public class SyncCreateBillingAccount { + + public static void main(String[] args) throws Exception { + syncCreateBillingAccount(); + } + + public static void syncCreateBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + CreateBillingAccountRequest request = + CreateBillingAccountRequest.newBuilder() + .setBillingAccount(BillingAccount.newBuilder().build()) + .build(); + BillingAccount response = cloudBillingClient.createBillingAccount(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_createbillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccountBillingaccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccountBillingaccount.java new file mode 100644 index 00000000..6e2234e1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/createbillingaccount/SyncCreateBillingAccountBillingaccount.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_createbillingaccount_billingaccount_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; + +public class SyncCreateBillingAccountBillingaccount { + + public static void main(String[] args) throws Exception { + syncCreateBillingAccountBillingaccount(); + } + + public static void syncCreateBillingAccountBillingaccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + BillingAccount billingAccount = BillingAccount.newBuilder().build(); + BillingAccount response = cloudBillingClient.createBillingAccount(billingAccount); + } + } +} +// [END billing_v1_generated_cloudbillingclient_createbillingaccount_billingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/AsyncGetBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/AsyncGetBillingAccount.java new file mode 100644 index 00000000..af572be6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/AsyncGetBillingAccount.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getbillingaccount_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.GetBillingAccountRequest; + +public class AsyncGetBillingAccount { + + public static void main(String[] args) throws Exception { + asyncGetBillingAccount(); + } + + public static void asyncGetBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + GetBillingAccountRequest request = + GetBillingAccountRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .build(); + ApiFuture future = + cloudBillingClient.getBillingAccountCallable().futureCall(request); + // Do something. + BillingAccount response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getbillingaccount_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccount.java new file mode 100644 index 00000000..c340d818 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccount.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getbillingaccount_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.GetBillingAccountRequest; + +public class SyncGetBillingAccount { + + public static void main(String[] args) throws Exception { + syncGetBillingAccount(); + } + + public static void syncGetBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + GetBillingAccountRequest request = + GetBillingAccountRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .build(); + BillingAccount response = cloudBillingClient.getBillingAccount(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getbillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountBillingaccountname.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountBillingaccountname.java new file mode 100644 index 00000000..c2455843 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountBillingaccountname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getbillingaccount_billingaccountname_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; + +public class SyncGetBillingAccountBillingaccountname { + + public static void main(String[] args) throws Exception { + syncGetBillingAccountBillingaccountname(); + } + + public static void syncGetBillingAccountBillingaccountname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + BillingAccount response = cloudBillingClient.getBillingAccount(name); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getbillingaccount_billingaccountname_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountString.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountString.java new file mode 100644 index 00000000..2ad8ab2b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getbillingaccount/SyncGetBillingAccountString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getbillingaccount_string_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; + +public class SyncGetBillingAccountString { + + public static void main(String[] args) throws Exception { + syncGetBillingAccountString(); + } + + public static void syncGetBillingAccountString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String name = BillingAccountName.of("[BILLING_ACCOUNT]").toString(); + BillingAccount response = cloudBillingClient.getBillingAccount(name); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getbillingaccount_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/AsyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 00000000..2cec2add --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = cloudBillingClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicy.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 00000000..de2070c6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getiampolicy_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = cloudBillingClient.getIamPolicy(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyResourcename.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyResourcename.java new file mode 100644 index 00000000..755725a7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyResourcename.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getiampolicy_resourcename_sync] +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.Policy; + +public class SyncGetIamPolicyResourcename { + + public static void main(String[] args) throws Exception { + syncGetIamPolicyResourcename(); + } + + public static void syncGetIamPolicyResourcename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + Policy response = cloudBillingClient.getIamPolicy(resource); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getiampolicy_resourcename_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyString.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyString.java new file mode 100644 index 00000000..d0b45f5c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getiampolicy/SyncGetIamPolicyString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getiampolicy_string_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.Policy; + +public class SyncGetIamPolicyString { + + public static void main(String[] args) throws Exception { + syncGetIamPolicyString(); + } + + public static void syncGetIamPolicyString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String resource = BillingAccountName.of("[BILLING_ACCOUNT]").toString(); + Policy response = cloudBillingClient.getIamPolicy(resource); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getiampolicy_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/AsyncGetProjectBillingInfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/AsyncGetProjectBillingInfo.java new file mode 100644 index 00000000..f3b052a3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/AsyncGetProjectBillingInfo.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getprojectbillinginfo_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.GetProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class AsyncGetProjectBillingInfo { + + public static void main(String[] args) throws Exception { + asyncGetProjectBillingInfo(); + } + + public static void asyncGetProjectBillingInfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + GetProjectBillingInfoRequest request = + GetProjectBillingInfoRequest.newBuilder().setName("name3373707").build(); + ApiFuture future = + cloudBillingClient.getProjectBillingInfoCallable().futureCall(request); + // Do something. + ProjectBillingInfo response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getprojectbillinginfo_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfo.java new file mode 100644 index 00000000..f2a0d7d0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfo.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getprojectbillinginfo_sync] +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.GetProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class SyncGetProjectBillingInfo { + + public static void main(String[] args) throws Exception { + syncGetProjectBillingInfo(); + } + + public static void syncGetProjectBillingInfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + GetProjectBillingInfoRequest request = + GetProjectBillingInfoRequest.newBuilder().setName("name3373707").build(); + ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getprojectbillinginfo_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfoString.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfoString.java new file mode 100644 index 00000000..10abc0d3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/getprojectbillinginfo/SyncGetProjectBillingInfoString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_getprojectbillinginfo_string_sync] +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class SyncGetProjectBillingInfoString { + + public static void main(String[] args) throws Exception { + syncGetProjectBillingInfoString(); + } + + public static void syncGetProjectBillingInfoString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String name = "name3373707"; + ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(name); + } + } +} +// [END billing_v1_generated_cloudbillingclient_getprojectbillinginfo_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccounts.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccounts.java new file mode 100644 index 00000000..9e0c74e9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccounts.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listbillingaccounts_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ListBillingAccountsRequest; + +public class AsyncListBillingAccounts { + + public static void main(String[] args) throws Exception { + asyncListBillingAccounts(); + } + + public static void asyncListBillingAccounts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ListBillingAccountsRequest request = + ListBillingAccountsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + cloudBillingClient.listBillingAccountsPagedCallable().futureCall(request); + // Do something. + for (BillingAccount element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listbillingaccounts_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccountsPaged.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccountsPaged.java new file mode 100644 index 00000000..e32c1a8a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/AsyncListBillingAccountsPaged.java @@ -0,0 +1,58 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listbillingaccounts_paged_async] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ListBillingAccountsRequest; +import com.google.cloud.billing.v1.ListBillingAccountsResponse; +import com.google.common.base.Strings; + +public class AsyncListBillingAccountsPaged { + + public static void main(String[] args) throws Exception { + asyncListBillingAccountsPaged(); + } + + public static void asyncListBillingAccountsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ListBillingAccountsRequest request = + ListBillingAccountsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListBillingAccountsResponse response = + cloudBillingClient.listBillingAccountsCallable().call(request); + for (BillingAccount element : response.getBillingAccountsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listbillingaccounts_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccounts.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccounts.java new file mode 100644 index 00000000..02b6a6e0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccounts.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listbillingaccounts_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ListBillingAccountsRequest; + +public class SyncListBillingAccounts { + + public static void main(String[] args) throws Exception { + syncListBillingAccounts(); + } + + public static void syncListBillingAccounts() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ListBillingAccountsRequest request = + ListBillingAccountsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (BillingAccount element : cloudBillingClient.listBillingAccounts(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listbillingaccounts_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccountsNoargs.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccountsNoargs.java new file mode 100644 index 00000000..ae1e91d3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listbillingaccounts/SyncListBillingAccountsNoargs.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listbillingaccounts_noargs_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.CloudBillingClient; + +public class SyncListBillingAccountsNoargs { + + public static void main(String[] args) throws Exception { + syncListBillingAccountsNoargs(); + } + + public static void syncListBillingAccountsNoargs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + for (BillingAccount element : cloudBillingClient.listBillingAccounts().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listbillingaccounts_noargs_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfo.java new file mode 100644 index 00000000..ef970e85 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfo.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listprojectbillinginfo_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ListProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class AsyncListProjectBillingInfo { + + public static void main(String[] args) throws Exception { + asyncListProjectBillingInfo(); + } + + public static void asyncListProjectBillingInfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ListProjectBillingInfoRequest request = + ListProjectBillingInfoRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + cloudBillingClient.listProjectBillingInfoPagedCallable().futureCall(request); + // Do something. + for (ProjectBillingInfo element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listprojectbillinginfo_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfoPaged.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfoPaged.java new file mode 100644 index 00000000..2b49388e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/AsyncListProjectBillingInfoPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listprojectbillinginfo_paged_async] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ListProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ListProjectBillingInfoResponse; +import com.google.cloud.billing.v1.ProjectBillingInfo; +import com.google.common.base.Strings; + +public class AsyncListProjectBillingInfoPaged { + + public static void main(String[] args) throws Exception { + asyncListProjectBillingInfoPaged(); + } + + public static void asyncListProjectBillingInfoPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ListProjectBillingInfoRequest request = + ListProjectBillingInfoRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListProjectBillingInfoResponse response = + cloudBillingClient.listProjectBillingInfoCallable().call(request); + for (ProjectBillingInfo element : response.getProjectBillingInfoList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listprojectbillinginfo_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfo.java new file mode 100644 index 00000000..e976f8f2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfo.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listprojectbillinginfo_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ListProjectBillingInfoRequest; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class SyncListProjectBillingInfo { + + public static void main(String[] args) throws Exception { + syncListProjectBillingInfo(); + } + + public static void syncListProjectBillingInfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ListProjectBillingInfoRequest request = + ListProjectBillingInfoRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (ProjectBillingInfo element : + cloudBillingClient.listProjectBillingInfo(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listprojectbillinginfo_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoBillingaccountname.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoBillingaccountname.java new file mode 100644 index 00000000..40a59519 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoBillingaccountname.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listprojectbillinginfo_billingaccountname_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class SyncListProjectBillingInfoBillingaccountname { + + public static void main(String[] args) throws Exception { + syncListProjectBillingInfoBillingaccountname(); + } + + public static void syncListProjectBillingInfoBillingaccountname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + for (ProjectBillingInfo element : + cloudBillingClient.listProjectBillingInfo(name).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listprojectbillinginfo_billingaccountname_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoString.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoString.java new file mode 100644 index 00000000..18723263 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/listprojectbillinginfo/SyncListProjectBillingInfoString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_listprojectbillinginfo_string_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class SyncListProjectBillingInfoString { + + public static void main(String[] args) throws Exception { + syncListProjectBillingInfoString(); + } + + public static void syncListProjectBillingInfoString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String name = BillingAccountName.of("[BILLING_ACCOUNT]").toString(); + for (ProjectBillingInfo element : + cloudBillingClient.listProjectBillingInfo(name).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudbillingclient_listprojectbillinginfo_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/AsyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 00000000..6e2cb5f4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_setiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = cloudBillingClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_setiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicy.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 00000000..6aab84a5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_setiampolicy_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = cloudBillingClient.setIamPolicy(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_setiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyResourcenamePolicy.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyResourcenamePolicy.java new file mode 100644 index 00000000..9cca970a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyResourcenamePolicy.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_setiampolicy_resourcenamepolicy_sync] +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.Policy; + +public class SyncSetIamPolicyResourcenamePolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicyResourcenamePolicy(); + } + + public static void syncSetIamPolicyResourcenamePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + Policy policy = Policy.newBuilder().build(); + Policy response = cloudBillingClient.setIamPolicy(resource, policy); + } + } +} +// [END billing_v1_generated_cloudbillingclient_setiampolicy_resourcenamepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyStringPolicy.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyStringPolicy.java new file mode 100644 index 00000000..2146a4b5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/setiampolicy/SyncSetIamPolicyStringPolicy.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_setiampolicy_stringpolicy_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.Policy; + +public class SyncSetIamPolicyStringPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicyStringPolicy(); + } + + public static void syncSetIamPolicyStringPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String resource = BillingAccountName.of("[BILLING_ACCOUNT]").toString(); + Policy policy = Policy.newBuilder().build(); + Policy response = cloudBillingClient.setIamPolicy(resource, policy); + } + } +} +// [END billing_v1_generated_cloudbillingclient_setiampolicy_stringpolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/AsyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 00000000..55d80c9f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_testiampermissions_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + cloudBillingClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_testiampermissions_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissions.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 00000000..e62adb83 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_testiampermissions_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = cloudBillingClient.testIamPermissions(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_testiampermissions_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsResourcenameListstring.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsResourcenameListstring.java new file mode 100644 index 00000000..de67d971 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsResourcenameListstring.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_testiampermissions_resourcenameliststring_sync] +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; +import java.util.List; + +public class SyncTestIamPermissionsResourcenameListstring { + + public static void main(String[] args) throws Exception { + syncTestIamPermissionsResourcenameListstring(); + } + + public static void syncTestIamPermissionsResourcenameListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); + List permissions = new ArrayList<>(); + TestIamPermissionsResponse response = + cloudBillingClient.testIamPermissions(resource, permissions); + } + } +} +// [END billing_v1_generated_cloudbillingclient_testiampermissions_resourcenameliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsStringListstring.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsStringListstring.java new file mode 100644 index 00000000..b632396c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/testiampermissions/SyncTestIamPermissionsStringListstring.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_testiampermissions_stringliststring_sync] +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.iam.v1.TestIamPermissionsResponse; +import java.util.ArrayList; +import java.util.List; + +public class SyncTestIamPermissionsStringListstring { + + public static void main(String[] args) throws Exception { + syncTestIamPermissionsStringListstring(); + } + + public static void syncTestIamPermissionsStringListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String resource = BillingAccountName.of("[BILLING_ACCOUNT]").toString(); + List permissions = new ArrayList<>(); + TestIamPermissionsResponse response = + cloudBillingClient.testIamPermissions(resource, permissions); + } + } +} +// [END billing_v1_generated_cloudbillingclient_testiampermissions_stringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/AsyncUpdateBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/AsyncUpdateBillingAccount.java new file mode 100644 index 00000000..d8c693d3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/AsyncUpdateBillingAccount.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_updatebillingaccount_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.UpdateBillingAccountRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateBillingAccount { + + public static void main(String[] args) throws Exception { + asyncUpdateBillingAccount(); + } + + public static void asyncUpdateBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + UpdateBillingAccountRequest request = + UpdateBillingAccountRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setAccount(BillingAccount.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + cloudBillingClient.updateBillingAccountCallable().futureCall(request); + // Do something. + BillingAccount response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_updatebillingaccount_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccount.java new file mode 100644 index 00000000..bc824e77 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccount.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_updatebillingaccount_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.UpdateBillingAccountRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateBillingAccount { + + public static void main(String[] args) throws Exception { + syncUpdateBillingAccount(); + } + + public static void syncUpdateBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + UpdateBillingAccountRequest request = + UpdateBillingAccountRequest.newBuilder() + .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) + .setAccount(BillingAccount.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + BillingAccount response = cloudBillingClient.updateBillingAccount(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_updatebillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountBillingaccountnameBillingaccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountBillingaccountnameBillingaccount.java new file mode 100644 index 00000000..8be02916 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountBillingaccountnameBillingaccount.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START +// billing_v1_generated_cloudbillingclient_updatebillingaccount_billingaccountnamebillingaccount_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; + +public class SyncUpdateBillingAccountBillingaccountnameBillingaccount { + + public static void main(String[] args) throws Exception { + syncUpdateBillingAccountBillingaccountnameBillingaccount(); + } + + public static void syncUpdateBillingAccountBillingaccountnameBillingaccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); + BillingAccount account = BillingAccount.newBuilder().build(); + BillingAccount response = cloudBillingClient.updateBillingAccount(name, account); + } + } +} +// [END +// billing_v1_generated_cloudbillingclient_updatebillingaccount_billingaccountnamebillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountStringBillingaccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountStringBillingaccount.java new file mode 100644 index 00000000..ef7241f3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updatebillingaccount/SyncUpdateBillingAccountStringBillingaccount.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_updatebillingaccount_stringbillingaccount_sync] +import com.google.cloud.billing.v1.BillingAccount; +import com.google.cloud.billing.v1.BillingAccountName; +import com.google.cloud.billing.v1.CloudBillingClient; + +public class SyncUpdateBillingAccountStringBillingaccount { + + public static void main(String[] args) throws Exception { + syncUpdateBillingAccountStringBillingaccount(); + } + + public static void syncUpdateBillingAccountStringBillingaccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String name = BillingAccountName.of("[BILLING_ACCOUNT]").toString(); + BillingAccount account = BillingAccount.newBuilder().build(); + BillingAccount response = cloudBillingClient.updateBillingAccount(name, account); + } + } +} +// [END billing_v1_generated_cloudbillingclient_updatebillingaccount_stringbillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/AsyncUpdateProjectBillingInfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/AsyncUpdateProjectBillingInfo.java new file mode 100644 index 00000000..e8955a7c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/AsyncUpdateProjectBillingInfo.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_updateprojectbillinginfo_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ProjectBillingInfo; +import com.google.cloud.billing.v1.UpdateProjectBillingInfoRequest; + +public class AsyncUpdateProjectBillingInfo { + + public static void main(String[] args) throws Exception { + asyncUpdateProjectBillingInfo(); + } + + public static void asyncUpdateProjectBillingInfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + UpdateProjectBillingInfoRequest request = + UpdateProjectBillingInfoRequest.newBuilder() + .setName("name3373707") + .setProjectBillingInfo(ProjectBillingInfo.newBuilder().build()) + .build(); + ApiFuture future = + cloudBillingClient.updateProjectBillingInfoCallable().futureCall(request); + // Do something. + ProjectBillingInfo response = future.get(); + } + } +} +// [END billing_v1_generated_cloudbillingclient_updateprojectbillinginfo_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfo.java new file mode 100644 index 00000000..0f5a1cac --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfo.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingclient_updateprojectbillinginfo_sync] +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ProjectBillingInfo; +import com.google.cloud.billing.v1.UpdateProjectBillingInfoRequest; + +public class SyncUpdateProjectBillingInfo { + + public static void main(String[] args) throws Exception { + syncUpdateProjectBillingInfo(); + } + + public static void syncUpdateProjectBillingInfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + UpdateProjectBillingInfoRequest request = + UpdateProjectBillingInfoRequest.newBuilder() + .setName("name3373707") + .setProjectBillingInfo(ProjectBillingInfo.newBuilder().build()) + .build(); + ProjectBillingInfo response = cloudBillingClient.updateProjectBillingInfo(request); + } + } +} +// [END billing_v1_generated_cloudbillingclient_updateprojectbillinginfo_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfoStringProjectbillinginfo.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfoStringProjectbillinginfo.java new file mode 100644 index 00000000..6dff2277 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingclient/updateprojectbillinginfo/SyncUpdateProjectBillingInfoStringProjectbillinginfo.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START +// billing_v1_generated_cloudbillingclient_updateprojectbillinginfo_stringprojectbillinginfo_sync] +import com.google.cloud.billing.v1.CloudBillingClient; +import com.google.cloud.billing.v1.ProjectBillingInfo; + +public class SyncUpdateProjectBillingInfoStringProjectbillinginfo { + + public static void main(String[] args) throws Exception { + syncUpdateProjectBillingInfoStringProjectbillinginfo(); + } + + public static void syncUpdateProjectBillingInfoStringProjectbillinginfo() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) { + String name = "name3373707"; + ProjectBillingInfo projectBillingInfo = ProjectBillingInfo.newBuilder().build(); + ProjectBillingInfo response = + cloudBillingClient.updateProjectBillingInfo(name, projectBillingInfo); + } + } +} +// [END +// billing_v1_generated_cloudbillingclient_updateprojectbillinginfo_stringprojectbillinginfo_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingsettings/getbillingaccount/SyncGetBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingsettings/getbillingaccount/SyncGetBillingAccount.java new file mode 100644 index 00000000..5ddb80f3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudbillingsettings/getbillingaccount/SyncGetBillingAccount.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudbillingsettings_getbillingaccount_sync] +import com.google.cloud.billing.v1.CloudBillingSettings; +import java.time.Duration; + +public class SyncGetBillingAccount { + + public static void main(String[] args) throws Exception { + syncGetBillingAccount(); + } + + public static void syncGetBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudBillingSettings.Builder cloudBillingSettingsBuilder = CloudBillingSettings.newBuilder(); + cloudBillingSettingsBuilder + .getBillingAccountSettings() + .setRetrySettings( + cloudBillingSettingsBuilder + .getBillingAccountSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudBillingSettings cloudBillingSettings = cloudBillingSettingsBuilder.build(); + } +} +// [END billing_v1_generated_cloudbillingsettings_getbillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..1ea7e9b7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.CloudCatalogSettings; +import com.google.cloud.billing.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudCatalogSettings cloudCatalogSettings = + CloudCatalogSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create(cloudCatalogSettings); + } +} +// [END billing_v1_generated_cloudcatalogclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..41b4ab8e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_create_setcredentialsprovider1_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.CloudCatalogSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudCatalogSettings cloudCatalogSettings = + CloudCatalogSettings.newBuilder() + .setTransportChannelProvider( + CloudCatalogSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create(cloudCatalogSettings); + } +} +// [END billing_v1_generated_cloudcatalogclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..509630bc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_create_setendpoint_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.CloudCatalogSettings; +import com.google.cloud.billing.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudCatalogSettings cloudCatalogSettings = + CloudCatalogSettings.newBuilder().setEndpoint(myEndpoint).build(); + CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create(cloudCatalogSettings); + } +} +// [END billing_v1_generated_cloudcatalogclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServices.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServices.java new file mode 100644 index 00000000..01002514 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServices.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listservices_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ListServicesRequest; +import com.google.cloud.billing.v1.Service; + +public class AsyncListServices { + + public static void main(String[] args) throws Exception { + asyncListServices(); + } + + public static void asyncListServices() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + cloudCatalogClient.listServicesPagedCallable().futureCall(request); + // Do something. + for (Service element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listservices_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServicesPaged.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServicesPaged.java new file mode 100644 index 00000000..cff8ea78 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/AsyncListServicesPaged.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listservices_paged_async] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ListServicesRequest; +import com.google.cloud.billing.v1.ListServicesResponse; +import com.google.cloud.billing.v1.Service; +import com.google.common.base.Strings; + +public class AsyncListServicesPaged { + + public static void main(String[] args) throws Exception { + asyncListServicesPaged(); + } + + public static void asyncListServicesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListServicesResponse response = cloudCatalogClient.listServicesCallable().call(request); + for (Service element : response.getServicesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listservices_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServices.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServices.java new file mode 100644 index 00000000..2e011ead --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServices.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listservices_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ListServicesRequest; +import com.google.cloud.billing.v1.Service; + +public class SyncListServices { + + public static void main(String[] args) throws Exception { + syncListServices(); + } + + public static void syncListServices() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ListServicesRequest request = + ListServicesRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Service element : cloudCatalogClient.listServices(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listservices_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServicesNoargs.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServicesNoargs.java new file mode 100644 index 00000000..51705975 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listservices/SyncListServicesNoargs.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listservices_noargs_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.Service; + +public class SyncListServicesNoargs { + + public static void main(String[] args) throws Exception { + syncListServicesNoargs(); + } + + public static void syncListServicesNoargs() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + for (Service element : cloudCatalogClient.listServices().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listservices_noargs_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkus.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkus.java new file mode 100644 index 00000000..295ee8ed --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkus.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listskus_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ListSkusRequest; +import com.google.cloud.billing.v1.ServiceName; +import com.google.cloud.billing.v1.Sku; +import com.google.protobuf.Timestamp; + +public class AsyncListSkus { + + public static void main(String[] args) throws Exception { + asyncListSkus(); + } + + public static void asyncListSkus() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ListSkusRequest request = + ListSkusRequest.newBuilder() + .setParent(ServiceName.of("[SERVICE]").toString()) + .setStartTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .setCurrencyCode("currencyCode1004773790") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = cloudCatalogClient.listSkusPagedCallable().futureCall(request); + // Do something. + for (Sku element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listskus_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkusPaged.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkusPaged.java new file mode 100644 index 00000000..1c3c2212 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/AsyncListSkusPaged.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listskus_paged_async] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ListSkusRequest; +import com.google.cloud.billing.v1.ListSkusResponse; +import com.google.cloud.billing.v1.ServiceName; +import com.google.cloud.billing.v1.Sku; +import com.google.common.base.Strings; +import com.google.protobuf.Timestamp; + +public class AsyncListSkusPaged { + + public static void main(String[] args) throws Exception { + asyncListSkusPaged(); + } + + public static void asyncListSkusPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ListSkusRequest request = + ListSkusRequest.newBuilder() + .setParent(ServiceName.of("[SERVICE]").toString()) + .setStartTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .setCurrencyCode("currencyCode1004773790") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListSkusResponse response = cloudCatalogClient.listSkusCallable().call(request); + for (Sku element : response.getSkusList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listskus_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkus.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkus.java new file mode 100644 index 00000000..34df60c8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkus.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listskus_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ListSkusRequest; +import com.google.cloud.billing.v1.ServiceName; +import com.google.cloud.billing.v1.Sku; +import com.google.protobuf.Timestamp; + +public class SyncListSkus { + + public static void main(String[] args) throws Exception { + syncListSkus(); + } + + public static void syncListSkus() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ListSkusRequest request = + ListSkusRequest.newBuilder() + .setParent(ServiceName.of("[SERVICE]").toString()) + .setStartTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .setCurrencyCode("currencyCode1004773790") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Sku element : cloudCatalogClient.listSkus(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listskus_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusServicename.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusServicename.java new file mode 100644 index 00000000..715f38b6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusServicename.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listskus_servicename_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ServiceName; +import com.google.cloud.billing.v1.Sku; + +public class SyncListSkusServicename { + + public static void main(String[] args) throws Exception { + syncListSkusServicename(); + } + + public static void syncListSkusServicename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + ServiceName parent = ServiceName.of("[SERVICE]"); + for (Sku element : cloudCatalogClient.listSkus(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listskus_servicename_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusString.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusString.java new file mode 100644 index 00000000..386319f9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogclient/listskus/SyncListSkusString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogclient_listskus_string_sync] +import com.google.cloud.billing.v1.CloudCatalogClient; +import com.google.cloud.billing.v1.ServiceName; +import com.google.cloud.billing.v1.Sku; + +public class SyncListSkusString { + + public static void main(String[] args) throws Exception { + syncListSkusString(); + } + + public static void syncListSkusString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CloudCatalogClient cloudCatalogClient = CloudCatalogClient.create()) { + String parent = ServiceName.of("[SERVICE]").toString(); + for (Sku element : cloudCatalogClient.listSkus(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END billing_v1_generated_cloudcatalogclient_listskus_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogsettings/listservices/SyncListServices.java b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogsettings/listservices/SyncListServices.java new file mode 100644 index 00000000..19d30147 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/cloudcatalogsettings/listservices/SyncListServices.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.samples; + +// [START billing_v1_generated_cloudcatalogsettings_listservices_sync] +import com.google.cloud.billing.v1.CloudCatalogSettings; +import java.time.Duration; + +public class SyncListServices { + + public static void main(String[] args) throws Exception { + syncListServices(); + } + + public static void syncListServices() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudCatalogSettings.Builder cloudCatalogSettingsBuilder = CloudCatalogSettings.newBuilder(); + cloudCatalogSettingsBuilder + .listServicesSettings() + .setRetrySettings( + cloudCatalogSettingsBuilder + .listServicesSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudCatalogSettings cloudCatalogSettings = cloudCatalogSettingsBuilder.build(); + } +} +// [END billing_v1_generated_cloudcatalogsettings_listservices_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudbillingstubsettings/getbillingaccount/SyncGetBillingAccount.java b/samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudbillingstubsettings/getbillingaccount/SyncGetBillingAccount.java new file mode 100644 index 00000000..33e52bda --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudbillingstubsettings/getbillingaccount/SyncGetBillingAccount.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.stub.samples; + +// [START billing_v1_generated_cloudbillingstubsettings_getbillingaccount_sync] +import com.google.cloud.billing.v1.stub.CloudBillingStubSettings; +import java.time.Duration; + +public class SyncGetBillingAccount { + + public static void main(String[] args) throws Exception { + syncGetBillingAccount(); + } + + public static void syncGetBillingAccount() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudBillingStubSettings.Builder cloudBillingSettingsBuilder = + CloudBillingStubSettings.newBuilder(); + cloudBillingSettingsBuilder + .getBillingAccountSettings() + .setRetrySettings( + cloudBillingSettingsBuilder + .getBillingAccountSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudBillingStubSettings cloudBillingSettings = cloudBillingSettingsBuilder.build(); + } +} +// [END billing_v1_generated_cloudbillingstubsettings_getbillingaccount_sync] diff --git a/samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudcatalogstubsettings/listservices/SyncListServices.java b/samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudcatalogstubsettings/listservices/SyncListServices.java new file mode 100644 index 00000000..5f68fb07 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/billing/v1/stub/cloudcatalogstubsettings/listservices/SyncListServices.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.billing.v1.stub.samples; + +// [START billing_v1_generated_cloudcatalogstubsettings_listservices_sync] +import com.google.cloud.billing.v1.stub.CloudCatalogStubSettings; +import java.time.Duration; + +public class SyncListServices { + + public static void main(String[] args) throws Exception { + syncListServices(); + } + + public static void syncListServices() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CloudCatalogStubSettings.Builder cloudCatalogSettingsBuilder = + CloudCatalogStubSettings.newBuilder(); + cloudCatalogSettingsBuilder + .listServicesSettings() + .setRetrySettings( + cloudCatalogSettingsBuilder + .listServicesSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CloudCatalogStubSettings cloudCatalogSettings = cloudCatalogSettingsBuilder.build(); + } +} +// [END billing_v1_generated_cloudcatalogstubsettings_listservices_sync]