Skip to content

Commit

Permalink
feat: [cloudbilling] added resource_reference for name in GetProjectB…
Browse files Browse the repository at this point in the history
…illingInfoRequest 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=
  • Loading branch information
gcf-owl-bot[bot] committed Jun 23, 2023
1 parent 0b25cfa commit cf43432
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 195 deletions.
2 changes: 1 addition & 1 deletion java-billing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.16.0</version>
<version>26.17.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,40 @@ public final ListProjectBillingInfoPagedResponse listProjectBillingInfo(
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
* String name = "name3373707";
* ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
* ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(name);
* }
* }</pre>
*
* @param name Required. The resource name of the project for which billing information is
* retrieved. For example, `projects/tokyo-rain-123`.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ProjectBillingInfo getProjectBillingInfo(ProjectBillingInfoName name) {
GetProjectBillingInfoRequest request =
GetProjectBillingInfoRequest.newBuilder()
.setName(name == null ? null : name.toString())
.build();
return getProjectBillingInfo(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets the billing information for a project. The current authenticated user must have the
* `resourcemanager.projects.get` permission for the project, which can be granted by assigning
* the [Project Viewer](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles)
* role.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
* String name = ProjectBillingInfoName.of("[PROJECT]").toString();
* ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(name);
* }
* }</pre>
Expand Down Expand Up @@ -920,7 +953,9 @@ public final ProjectBillingInfo getProjectBillingInfo(String name) {
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
* GetProjectBillingInfoRequest request =
* GetProjectBillingInfoRequest.newBuilder().setName("name3373707").build();
* GetProjectBillingInfoRequest.newBuilder()
* .setName(ProjectBillingInfoName.of("[PROJECT]").toString())
* .build();
* ProjectBillingInfo response = cloudBillingClient.getProjectBillingInfo(request);
* }
* }</pre>
Expand Down Expand Up @@ -949,7 +984,9 @@ public final ProjectBillingInfo getProjectBillingInfo(GetProjectBillingInfoReque
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (CloudBillingClient cloudBillingClient = CloudBillingClient.create()) {
* GetProjectBillingInfoRequest request =
* GetProjectBillingInfoRequest.newBuilder().setName("name3373707").build();
* GetProjectBillingInfoRequest.newBuilder()
* .setName(ProjectBillingInfoName.of("[PROJECT]").toString())
* .build();
* ApiFuture<ProjectBillingInfo> future =
* cloudBillingClient.getProjectBillingInfoCallable().futureCall(request);
* // Do something.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"methods": ["getIamPolicy", "getIamPolicy", "getIamPolicy", "getIamPolicyCallable"]
},
"GetProjectBillingInfo": {
"methods": ["getProjectBillingInfo", "getProjectBillingInfo", "getProjectBillingInfoCallable"]
"methods": ["getProjectBillingInfo", "getProjectBillingInfo", "getProjectBillingInfo", "getProjectBillingInfoCallable"]
},
"ListBillingAccounts": {
"methods": ["listBillingAccounts", "listBillingAccounts", "listBillingAccountsPagedCallable", "listBillingAccountsCallable"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

@Generated("by gapic-generator-java")
Expand Down Expand Up @@ -475,18 +476,19 @@ public void listProjectBillingInfoExceptionTest2() throws Exception {
}
}

@Ignore("Ignore until https://github.com/googleapis/sdk-platform-java/issues/1780 is resolved")
@Test
public void getProjectBillingInfoTest() throws Exception {
ProjectBillingInfo expectedResponse =
ProjectBillingInfo.newBuilder()
.setName("name3373707")
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
.setProjectId("projectId-894832108")
.setBillingAccountName("billingAccountName929322205")
.setBillingEnabled(true)
.build();
mockService.addResponse(expectedResponse);

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

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

try {
ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
client.getProjectBillingInfo(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}

@Test
public void getProjectBillingInfoTest2() throws Exception {
ProjectBillingInfo expectedResponse =
ProjectBillingInfo.newBuilder()
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
.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<String> 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 getProjectBillingInfoExceptionTest2() 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);
Expand All @@ -526,7 +575,7 @@ public void getProjectBillingInfoExceptionTest() throws Exception {
public void updateProjectBillingInfoTest() throws Exception {
ProjectBillingInfo expectedResponse =
ProjectBillingInfo.newBuilder()
.setName("name3373707")
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
.setProjectId("projectId-894832108")
.setBillingAccountName("billingAccountName929322205")
.setBillingEnabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,49 @@ public void listProjectBillingInfoExceptionTest2() throws Exception {
public void getProjectBillingInfoTest() throws Exception {
ProjectBillingInfo expectedResponse =
ProjectBillingInfo.newBuilder()
.setName("name3373707")
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
.setProjectId("projectId-894832108")
.setBillingAccountName("billingAccountName929322205")
.setBillingEnabled(true)
.build();
mockCloudBilling.addResponse(expectedResponse);

ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");

ProjectBillingInfo actualResponse = client.getProjectBillingInfo(name);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockCloudBilling.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetProjectBillingInfoRequest actualRequest =
((GetProjectBillingInfoRequest) actualRequests.get(0));

Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
public void getProjectBillingInfoExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockCloudBilling.addException(exception);

try {
ProjectBillingInfoName name = ProjectBillingInfoName.of("[PROJECT]");
client.getProjectBillingInfo(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}

@Test
public void getProjectBillingInfoTest2() throws Exception {
ProjectBillingInfo expectedResponse =
ProjectBillingInfo.newBuilder()
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
.setProjectId("projectId-894832108")
.setBillingAccountName("billingAccountName929322205")
.setBillingEnabled(true)
Expand All @@ -468,7 +510,7 @@ public void getProjectBillingInfoTest() throws Exception {
}

@Test
public void getProjectBillingInfoExceptionTest() throws Exception {
public void getProjectBillingInfoExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockCloudBilling.addException(exception);

Expand All @@ -485,7 +527,7 @@ public void getProjectBillingInfoExceptionTest() throws Exception {
public void updateProjectBillingInfoTest() throws Exception {
ProjectBillingInfo expectedResponse =
ProjectBillingInfo.newBuilder()
.setName("name3373707")
.setName(ProjectBillingInfoName.of("[PROJECT]").toString())
.setProjectId("projectId-894832108")
.setBillingAccountName("billingAccountName929322205")
.setBillingEnabled(true)
Expand Down
Loading

0 comments on commit cf43432

Please sign in to comment.