Skip to content

Commit cf43432

Browse files
feat: [cloudbilling] added resource_reference for name in GetProjectBillingInfoRequest message (#9555)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 541033608 Source-Link: https://togithub.com/googleapis/googleapis/commit/f78641709fd23336b303307ac4d55b5582b00fae Source-Link: https://togithub.com/googleapis/googleapis-gen/commit/c5986a104f1d765ce6b90160e05e6976693b38ef Copy-Tag: eyJwIjoiamF2YS1iaWxsaW5nLy5Pd2xCb3QueWFtbCIsImgiOiJjNTk4NmExMDRmMWQ3NjVjZTZiOTAxNjBlMDVlNjk3NjY5M2IzOGVmIn0=
1 parent 0b25cfa commit cf43432

File tree

16 files changed

+583
-195
lines changed

16 files changed

+583
-195
lines changed

java-billing/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
2020
<dependency>
2121
<groupId>com.google.cloud</groupId>
2222
<artifactId>libraries-bom</artifactId>
23-
<version>26.16.0</version>
23+
<version>26.17.0</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>

java-billing/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/CloudBillingClient.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,40 @@ public final ListProjectBillingInfoPagedResponse listProjectBillingInfo(
888888
* // - It may require specifying regional endpoints when creating the service client as shown in
889889
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
890890
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
891-
* String name = "name3373707";
891+
* ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
892+
* ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(name);
893+
* }
894+
* }</pre>
895+
*
896+
* @param name Required. The resource name of the project for which billing information is
897+
* retrieved. For example, `projects/tokyo-rain-123`.
898+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
899+
*/
900+
public final ProjectBillingInfo getProjectBillingInfo(ProjectBillingInfoName name) {
901+
GetProjectBillingInfoRequest request =
902+
GetProjectBillingInfoRequest.newBuilder()
903+
.setName(name == null ? null : name.toString())
904+
.build();
905+
return getProjectBillingInfo(request);
906+
}
907+
908+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
909+
/**
910+
* Gets the billing information for a project. The current authenticated user must have the
911+
* `resourcemanager.projects.get` permission for the project, which can be granted by assigning
912+
* the [Project Viewer](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles)
913+
* role.
914+
*
915+
* <p>Sample code:
916+
*
917+
* <pre>{@code
918+
* // This snippet has been automatically generated and should be regarded as a code template only.
919+
* // It will require modifications to work:
920+
* // - It may require correct/in-range values for request initialization.
921+
* // - It may require specifying regional endpoints when creating the service client as shown in
922+
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
923+
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
924+
* String name = ProjectBillingInfoName.of("[PROJECT]").toString();
892925
* ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(name);
893926
* }
894927
* }</pre>
@@ -920,7 +953,9 @@ public final ProjectBillingInfo getProjectBillingInfo(String name) {
920953
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
921954
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
922955
* GetProjectBillingInfoRequest request =
923-
* GetProjectBillingInfoRequest.newBuilder().setName("name3373707").build();
956+
* GetProjectBillingInfoRequest.newBuilder()
957+
* .setName(ProjectBillingInfoName.of("[PROJECT]").toString())
958+
* .build();
924959
* ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(request);
925960
* }
926961
* }</pre>
@@ -949,7 +984,9 @@ public final ProjectBillingInfo getProjectBillingInfo(GetProjectBillingInfoReque
949984
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
950985
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
951986
* GetProjectBillingInfoRequest request =
952-
* GetProjectBillingInfoRequest.newBuilder().setName("name3373707").build();
987+
* GetProjectBillingInfoRequest.newBuilder()
988+
* .setName(ProjectBillingInfoName.of("[PROJECT]").toString())
989+
* .build();
953990
* ApiFuture<ProjectBillingInfo> future =
954991
* cloudBillingClient.getProjectBillingInfoCallable().futureCall(request);
955992
* // Do something.

java-billing/google-cloud-billing/src/main/java/com/google/cloud/billing/v1/gapic_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"methods": ["getIamPolicy", "getIamPolicy", "getIamPolicy", "getIamPolicyCallable"]
2121
},
2222
"GetProjectBillingInfo": {
23-
"methods": ["getProjectBillingInfo", "getProjectBillingInfo", "getProjectBillingInfoCallable"]
23+
"methods": ["getProjectBillingInfo", "getProjectBillingInfo", "getProjectBillingInfo", "getProjectBillingInfoCallable"]
2424
},
2525
"ListBillingAccounts": {
2626
"methods": ["listBillingAccounts", "listBillingAccounts", "listBillingAccountsPagedCallable", "listBillingAccountsCallable"]

java-billing/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudBillingClientHttpJsonTest.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.junit.Assert;
4747
import org.junit.Before;
4848
import org.junit.BeforeClass;
49+
import org.junit.Ignore;
4950
import org.junit.Test;
5051

5152
@Generated("by gapic-generator-java")
@@ -475,18 +476,19 @@ public void listProjectBillingInfoExceptionTest2() throws Exception {
475476
}
476477
}
477478

479+
@Ignore("Ignore until https://github.com/googleapis/sdk-platform-java/issues/1780 is resolved")
478480
@Test
479481
public void getProjectBillingInfoTest() throws Exception {
480482
ProjectBillingInfo expectedResponse =
481483
ProjectBillingInfo.newBuilder()
482-
.setName("name3373707")
484+
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
483485
.setProjectId("projectId-894832108")
484486
.setBillingAccountName("billingAccountName929322205")
485487
.setBillingEnabled(true)
486488
.build();
487489
mockService.addResponse(expectedResponse);
488490

489-
String name = "projects/project-3664";
491+
ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
490492

491493
ProjectBillingInfo actualResponse = client.getProjectBillingInfo(name);
492494
Assert.assertEquals(expectedResponse, actualResponse);
@@ -513,6 +515,53 @@ public void getProjectBillingInfoExceptionTest() throws Exception {
513515
new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
514516
mockService.addException(exception);
515517

518+
try {
519+
ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
520+
client.getProjectBillingInfo(name);
521+
Assert.fail("No exception raised");
522+
} catch (InvalidArgumentException e) {
523+
// Expected exception.
524+
}
525+
}
526+
527+
@Test
528+
public void getProjectBillingInfoTest2() throws Exception {
529+
ProjectBillingInfo expectedResponse =
530+
ProjectBillingInfo.newBuilder()
531+
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
532+
.setProjectId("projectId-894832108")
533+
.setBillingAccountName("billingAccountName929322205")
534+
.setBillingEnabled(true)
535+
.build();
536+
mockService.addResponse(expectedResponse);
537+
538+
String name = "projects/project-3664";
539+
540+
ProjectBillingInfo actualResponse = client.getProjectBillingInfo(name);
541+
Assert.assertEquals(expectedResponse, actualResponse);
542+
543+
List<String> actualRequests = mockService.getRequestPaths();
544+
Assert.assertEquals(1, actualRequests.size());
545+
546+
String apiClientHeaderKey =
547+
mockService
548+
.getRequestHeaders()
549+
.get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
550+
.iterator()
551+
.next();
552+
Assert.assertTrue(
553+
GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
554+
.matcher(apiClientHeaderKey)
555+
.matches());
556+
}
557+
558+
@Test
559+
public void getProjectBillingInfoExceptionTest2() throws Exception {
560+
ApiException exception =
561+
ApiExceptionFactory.createException(
562+
new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
563+
mockService.addException(exception);
564+
516565
try {
517566
String name = "projects/project-3664";
518567
client.getProjectBillingInfo(name);
@@ -526,7 +575,7 @@ public void getProjectBillingInfoExceptionTest() throws Exception {
526575
public void updateProjectBillingInfoTest() throws Exception {
527576
ProjectBillingInfo expectedResponse =
528577
ProjectBillingInfo.newBuilder()
529-
.setName("name3373707")
578+
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
530579
.setProjectId("projectId-894832108")
531580
.setBillingAccountName("billingAccountName929322205")
532581
.setBillingEnabled(true)

java-billing/google-cloud-billing/src/test/java/com/google/cloud/billing/v1/CloudBillingClientTest.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,49 @@ public void listProjectBillingInfoExceptionTest2() throws Exception {
443443
public void getProjectBillingInfoTest() throws Exception {
444444
ProjectBillingInfo expectedResponse =
445445
ProjectBillingInfo.newBuilder()
446-
.setName("name3373707")
446+
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
447+
.setProjectId("projectId-894832108")
448+
.setBillingAccountName("billingAccountName929322205")
449+
.setBillingEnabled(true)
450+
.build();
451+
mockCloudBilling.addResponse(expectedResponse);
452+
453+
ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
454+
455+
ProjectBillingInfo actualResponse = client.getProjectBillingInfo(name);
456+
Assert.assertEquals(expectedResponse, actualResponse);
457+
458+
List<AbstractMessage> actualRequests = mockCloudBilling.getRequests();
459+
Assert.assertEquals(1, actualRequests.size());
460+
GetProjectBillingInfoRequest actualRequest =
461+
((GetProjectBillingInfoRequest) actualRequests.get(0));
462+
463+
Assert.assertEquals(name.toString(), actualRequest.getName());
464+
Assert.assertTrue(
465+
channelProvider.isHeaderSent(
466+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
467+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
468+
}
469+
470+
@Test
471+
public void getProjectBillingInfoExceptionTest() throws Exception {
472+
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
473+
mockCloudBilling.addException(exception);
474+
475+
try {
476+
ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
477+
client.getProjectBillingInfo(name);
478+
Assert.fail("No exception raised");
479+
} catch (InvalidArgumentException e) {
480+
// Expected exception.
481+
}
482+
}
483+
484+
@Test
485+
public void getProjectBillingInfoTest2() throws Exception {
486+
ProjectBillingInfo expectedResponse =
487+
ProjectBillingInfo.newBuilder()
488+
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
447489
.setProjectId("projectId-894832108")
448490
.setBillingAccountName("billingAccountName929322205")
449491
.setBillingEnabled(true)
@@ -468,7 +510,7 @@ public void getProjectBillingInfoTest() throws Exception {
468510
}
469511

470512
@Test
471-
public void getProjectBillingInfoExceptionTest() throws Exception {
513+
public void getProjectBillingInfoExceptionTest2() throws Exception {
472514
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
473515
mockCloudBilling.addException(exception);
474516

@@ -485,7 +527,7 @@ public void getProjectBillingInfoExceptionTest() throws Exception {
485527
public void updateProjectBillingInfoTest() throws Exception {
486528
ProjectBillingInfo expectedResponse =
487529
ProjectBillingInfo.newBuilder()
488-
.setName("name3373707")
530+
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
489531
.setProjectId("projectId-894832108")
490532
.setBillingAccountName("billingAccountName929322205")
491533
.setBillingEnabled(true)

0 commit comments

Comments
 (0)