1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.billing.v1; 18 19 import static com.google.cloud.billing.v1.CloudBillingClient.ListBillingAccountsPagedResponse; 20 import static com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse; 21 22 import com.google.api.gax.core.NoCredentialsProvider; 23 import com.google.api.gax.grpc.GaxGrpcProperties; 24 import com.google.api.gax.grpc.testing.LocalChannelProvider; 25 import com.google.api.gax.grpc.testing.MockGrpcService; 26 import com.google.api.gax.grpc.testing.MockServiceHelper; 27 import com.google.api.gax.rpc.ApiClientHeaderProvider; 28 import com.google.api.gax.rpc.InvalidArgumentException; 29 import com.google.api.resourcenames.ResourceName; 30 import com.google.common.collect.Lists; 31 import com.google.iam.v1.AuditConfig; 32 import com.google.iam.v1.Binding; 33 import com.google.iam.v1.GetIamPolicyRequest; 34 import com.google.iam.v1.Policy; 35 import com.google.iam.v1.SetIamPolicyRequest; 36 import com.google.iam.v1.TestIamPermissionsRequest; 37 import com.google.iam.v1.TestIamPermissionsResponse; 38 import com.google.protobuf.AbstractMessage; 39 import com.google.protobuf.ByteString; 40 import io.grpc.StatusRuntimeException; 41 import java.io.IOException; 42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import java.util.List; 45 import java.util.UUID; 46 import javax.annotation.Generated; 47 import org.junit.After; 48 import org.junit.AfterClass; 49 import org.junit.Assert; 50 import org.junit.Before; 51 import org.junit.BeforeClass; 52 import org.junit.Test; 53 54 @Generated("by gapic-generator-java") 55 public class CloudBillingClientTest { 56 private static MockCloudBilling mockCloudBilling; 57 private static MockServiceHelper mockServiceHelper; 58 private LocalChannelProvider channelProvider; 59 private CloudBillingClient client; 60 61 @BeforeClass startStaticServer()62 public static void startStaticServer() { 63 mockCloudBilling = new MockCloudBilling(); 64 mockServiceHelper = 65 new MockServiceHelper( 66 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockCloudBilling)); 67 mockServiceHelper.start(); 68 } 69 70 @AfterClass stopServer()71 public static void stopServer() { 72 mockServiceHelper.stop(); 73 } 74 75 @Before setUp()76 public void setUp() throws IOException { 77 mockServiceHelper.reset(); 78 channelProvider = mockServiceHelper.createChannelProvider(); 79 CloudBillingSettings settings = 80 CloudBillingSettings.newBuilder() 81 .setTransportChannelProvider(channelProvider) 82 .setCredentialsProvider(NoCredentialsProvider.create()) 83 .build(); 84 client = CloudBillingClient.create(settings); 85 } 86 87 @After tearDown()88 public void tearDown() throws Exception { 89 client.close(); 90 } 91 92 @Test getBillingAccountTest()93 public void getBillingAccountTest() throws Exception { 94 BillingAccount expectedResponse = 95 BillingAccount.newBuilder() 96 .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) 97 .setOpen(true) 98 .setDisplayName("displayName1714148973") 99 .setMasterBillingAccount("masterBillingAccount1488941620") 100 .build(); 101 mockCloudBilling.addResponse(expectedResponse); 102 103 BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); 104 105 BillingAccount actualResponse = client.getBillingAccount(name); 106 Assert.assertEquals(expectedResponse, actualResponse); 107 108 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 109 Assert.assertEquals(1, actualRequests.size()); 110 GetBillingAccountRequest actualRequest = ((GetBillingAccountRequest) actualRequests.get(0)); 111 112 Assert.assertEquals(name.toString(), actualRequest.getName()); 113 Assert.assertTrue( 114 channelProvider.isHeaderSent( 115 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 116 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 117 } 118 119 @Test getBillingAccountExceptionTest()120 public void getBillingAccountExceptionTest() throws Exception { 121 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 122 mockCloudBilling.addException(exception); 123 124 try { 125 BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); 126 client.getBillingAccount(name); 127 Assert.fail("No exception raised"); 128 } catch (InvalidArgumentException e) { 129 // Expected exception. 130 } 131 } 132 133 @Test getBillingAccountTest2()134 public void getBillingAccountTest2() throws Exception { 135 BillingAccount expectedResponse = 136 BillingAccount.newBuilder() 137 .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) 138 .setOpen(true) 139 .setDisplayName("displayName1714148973") 140 .setMasterBillingAccount("masterBillingAccount1488941620") 141 .build(); 142 mockCloudBilling.addResponse(expectedResponse); 143 144 String name = "name3373707"; 145 146 BillingAccount actualResponse = client.getBillingAccount(name); 147 Assert.assertEquals(expectedResponse, actualResponse); 148 149 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 150 Assert.assertEquals(1, actualRequests.size()); 151 GetBillingAccountRequest actualRequest = ((GetBillingAccountRequest) actualRequests.get(0)); 152 153 Assert.assertEquals(name, actualRequest.getName()); 154 Assert.assertTrue( 155 channelProvider.isHeaderSent( 156 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 157 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 158 } 159 160 @Test getBillingAccountExceptionTest2()161 public void getBillingAccountExceptionTest2() throws Exception { 162 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 163 mockCloudBilling.addException(exception); 164 165 try { 166 String name = "name3373707"; 167 client.getBillingAccount(name); 168 Assert.fail("No exception raised"); 169 } catch (InvalidArgumentException e) { 170 // Expected exception. 171 } 172 } 173 174 @Test listBillingAccountsTest()175 public void listBillingAccountsTest() throws Exception { 176 BillingAccount responsesElement = BillingAccount.newBuilder().build(); 177 ListBillingAccountsResponse expectedResponse = 178 ListBillingAccountsResponse.newBuilder() 179 .setNextPageToken("") 180 .addAllBillingAccounts(Arrays.asList(responsesElement)) 181 .build(); 182 mockCloudBilling.addResponse(expectedResponse); 183 184 ListBillingAccountsPagedResponse pagedListResponse = client.listBillingAccounts(); 185 186 List<BillingAccount> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 187 188 Assert.assertEquals(1, resources.size()); 189 Assert.assertEquals(expectedResponse.getBillingAccountsList().get(0), resources.get(0)); 190 191 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 192 Assert.assertEquals(1, actualRequests.size()); 193 ListBillingAccountsRequest actualRequest = ((ListBillingAccountsRequest) actualRequests.get(0)); 194 195 Assert.assertTrue( 196 channelProvider.isHeaderSent( 197 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 198 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 199 } 200 201 @Test listBillingAccountsExceptionTest()202 public void listBillingAccountsExceptionTest() throws Exception { 203 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 204 mockCloudBilling.addException(exception); 205 206 try { 207 ListBillingAccountsRequest request = 208 ListBillingAccountsRequest.newBuilder() 209 .setPageSize(883849137) 210 .setPageToken("pageToken873572522") 211 .setFilter("filter-1274492040") 212 .build(); 213 client.listBillingAccounts(request); 214 Assert.fail("No exception raised"); 215 } catch (InvalidArgumentException e) { 216 // Expected exception. 217 } 218 } 219 220 @Test updateBillingAccountTest()221 public void updateBillingAccountTest() throws Exception { 222 BillingAccount expectedResponse = 223 BillingAccount.newBuilder() 224 .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) 225 .setOpen(true) 226 .setDisplayName("displayName1714148973") 227 .setMasterBillingAccount("masterBillingAccount1488941620") 228 .build(); 229 mockCloudBilling.addResponse(expectedResponse); 230 231 BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); 232 BillingAccount account = BillingAccount.newBuilder().build(); 233 234 BillingAccount actualResponse = client.updateBillingAccount(name, account); 235 Assert.assertEquals(expectedResponse, actualResponse); 236 237 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 238 Assert.assertEquals(1, actualRequests.size()); 239 UpdateBillingAccountRequest actualRequest = 240 ((UpdateBillingAccountRequest) actualRequests.get(0)); 241 242 Assert.assertEquals(name.toString(), actualRequest.getName()); 243 Assert.assertEquals(account, actualRequest.getAccount()); 244 Assert.assertTrue( 245 channelProvider.isHeaderSent( 246 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 247 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 248 } 249 250 @Test updateBillingAccountExceptionTest()251 public void updateBillingAccountExceptionTest() throws Exception { 252 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 253 mockCloudBilling.addException(exception); 254 255 try { 256 BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); 257 BillingAccount account = BillingAccount.newBuilder().build(); 258 client.updateBillingAccount(name, account); 259 Assert.fail("No exception raised"); 260 } catch (InvalidArgumentException e) { 261 // Expected exception. 262 } 263 } 264 265 @Test updateBillingAccountTest2()266 public void updateBillingAccountTest2() throws Exception { 267 BillingAccount expectedResponse = 268 BillingAccount.newBuilder() 269 .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) 270 .setOpen(true) 271 .setDisplayName("displayName1714148973") 272 .setMasterBillingAccount("masterBillingAccount1488941620") 273 .build(); 274 mockCloudBilling.addResponse(expectedResponse); 275 276 String name = "name3373707"; 277 BillingAccount account = BillingAccount.newBuilder().build(); 278 279 BillingAccount actualResponse = client.updateBillingAccount(name, account); 280 Assert.assertEquals(expectedResponse, actualResponse); 281 282 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 283 Assert.assertEquals(1, actualRequests.size()); 284 UpdateBillingAccountRequest actualRequest = 285 ((UpdateBillingAccountRequest) actualRequests.get(0)); 286 287 Assert.assertEquals(name, actualRequest.getName()); 288 Assert.assertEquals(account, actualRequest.getAccount()); 289 Assert.assertTrue( 290 channelProvider.isHeaderSent( 291 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 292 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 293 } 294 295 @Test updateBillingAccountExceptionTest2()296 public void updateBillingAccountExceptionTest2() throws Exception { 297 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 298 mockCloudBilling.addException(exception); 299 300 try { 301 String name = "name3373707"; 302 BillingAccount account = BillingAccount.newBuilder().build(); 303 client.updateBillingAccount(name, account); 304 Assert.fail("No exception raised"); 305 } catch (InvalidArgumentException e) { 306 // Expected exception. 307 } 308 } 309 310 @Test createBillingAccountTest()311 public void createBillingAccountTest() throws Exception { 312 BillingAccount expectedResponse = 313 BillingAccount.newBuilder() 314 .setName(BillingAccountName.of("[BILLING_ACCOUNT]").toString()) 315 .setOpen(true) 316 .setDisplayName("displayName1714148973") 317 .setMasterBillingAccount("masterBillingAccount1488941620") 318 .build(); 319 mockCloudBilling.addResponse(expectedResponse); 320 321 BillingAccount billingAccount = BillingAccount.newBuilder().build(); 322 323 BillingAccount actualResponse = client.createBillingAccount(billingAccount); 324 Assert.assertEquals(expectedResponse, actualResponse); 325 326 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 327 Assert.assertEquals(1, actualRequests.size()); 328 CreateBillingAccountRequest actualRequest = 329 ((CreateBillingAccountRequest) actualRequests.get(0)); 330 331 Assert.assertEquals(billingAccount, actualRequest.getBillingAccount()); 332 Assert.assertTrue( 333 channelProvider.isHeaderSent( 334 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 335 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 336 } 337 338 @Test createBillingAccountExceptionTest()339 public void createBillingAccountExceptionTest() throws Exception { 340 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 341 mockCloudBilling.addException(exception); 342 343 try { 344 BillingAccount billingAccount = BillingAccount.newBuilder().build(); 345 client.createBillingAccount(billingAccount); 346 Assert.fail("No exception raised"); 347 } catch (InvalidArgumentException e) { 348 // Expected exception. 349 } 350 } 351 352 @Test listProjectBillingInfoTest()353 public void listProjectBillingInfoTest() throws Exception { 354 ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build(); 355 ListProjectBillingInfoResponse expectedResponse = 356 ListProjectBillingInfoResponse.newBuilder() 357 .setNextPageToken("") 358 .addAllProjectBillingInfo(Arrays.asList(responsesElement)) 359 .build(); 360 mockCloudBilling.addResponse(expectedResponse); 361 362 BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); 363 364 ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name); 365 366 List<ProjectBillingInfo> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 367 368 Assert.assertEquals(1, resources.size()); 369 Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0)); 370 371 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 372 Assert.assertEquals(1, actualRequests.size()); 373 ListProjectBillingInfoRequest actualRequest = 374 ((ListProjectBillingInfoRequest) actualRequests.get(0)); 375 376 Assert.assertEquals(name.toString(), actualRequest.getName()); 377 Assert.assertTrue( 378 channelProvider.isHeaderSent( 379 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 380 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 381 } 382 383 @Test listProjectBillingInfoExceptionTest()384 public void listProjectBillingInfoExceptionTest() throws Exception { 385 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 386 mockCloudBilling.addException(exception); 387 388 try { 389 BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]"); 390 client.listProjectBillingInfo(name); 391 Assert.fail("No exception raised"); 392 } catch (InvalidArgumentException e) { 393 // Expected exception. 394 } 395 } 396 397 @Test listProjectBillingInfoTest2()398 public void listProjectBillingInfoTest2() throws Exception { 399 ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build(); 400 ListProjectBillingInfoResponse expectedResponse = 401 ListProjectBillingInfoResponse.newBuilder() 402 .setNextPageToken("") 403 .addAllProjectBillingInfo(Arrays.asList(responsesElement)) 404 .build(); 405 mockCloudBilling.addResponse(expectedResponse); 406 407 String name = "name3373707"; 408 409 ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name); 410 411 List<ProjectBillingInfo> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 412 413 Assert.assertEquals(1, resources.size()); 414 Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0)); 415 416 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 417 Assert.assertEquals(1, actualRequests.size()); 418 ListProjectBillingInfoRequest actualRequest = 419 ((ListProjectBillingInfoRequest) actualRequests.get(0)); 420 421 Assert.assertEquals(name, actualRequest.getName()); 422 Assert.assertTrue( 423 channelProvider.isHeaderSent( 424 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 425 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 426 } 427 428 @Test listProjectBillingInfoExceptionTest2()429 public void listProjectBillingInfoExceptionTest2() throws Exception { 430 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 431 mockCloudBilling.addException(exception); 432 433 try { 434 String name = "name3373707"; 435 client.listProjectBillingInfo(name); 436 Assert.fail("No exception raised"); 437 } catch (InvalidArgumentException e) { 438 // Expected exception. 439 } 440 } 441 442 @Test getProjectBillingInfoTest()443 public void getProjectBillingInfoTest() throws Exception { 444 ProjectBillingInfo expectedResponse = 445 ProjectBillingInfo.newBuilder() 446 .setName("name3373707") 447 .setProjectId("projectId-894832108") 448 .setBillingAccountName("billingAccountName929322205") 449 .setBillingEnabled(true) 450 .build(); 451 mockCloudBilling.addResponse(expectedResponse); 452 453 String name = "name3373707"; 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, actualRequest.getName()); 464 Assert.assertTrue( 465 channelProvider.isHeaderSent( 466 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 467 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 468 } 469 470 @Test getProjectBillingInfoExceptionTest()471 public void getProjectBillingInfoExceptionTest() throws Exception { 472 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 473 mockCloudBilling.addException(exception); 474 475 try { 476 String name = "name3373707"; 477 client.getProjectBillingInfo(name); 478 Assert.fail("No exception raised"); 479 } catch (InvalidArgumentException e) { 480 // Expected exception. 481 } 482 } 483 484 @Test updateProjectBillingInfoTest()485 public void updateProjectBillingInfoTest() throws Exception { 486 ProjectBillingInfo expectedResponse = 487 ProjectBillingInfo.newBuilder() 488 .setName("name3373707") 489 .setProjectId("projectId-894832108") 490 .setBillingAccountName("billingAccountName929322205") 491 .setBillingEnabled(true) 492 .build(); 493 mockCloudBilling.addResponse(expectedResponse); 494 495 String name = "name3373707"; 496 ProjectBillingInfo projectBillingInfo = ProjectBillingInfo.newBuilder().build(); 497 498 ProjectBillingInfo actualResponse = client.updateProjectBillingInfo(name, projectBillingInfo); 499 Assert.assertEquals(expectedResponse, actualResponse); 500 501 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 502 Assert.assertEquals(1, actualRequests.size()); 503 UpdateProjectBillingInfoRequest actualRequest = 504 ((UpdateProjectBillingInfoRequest) actualRequests.get(0)); 505 506 Assert.assertEquals(name, actualRequest.getName()); 507 Assert.assertEquals(projectBillingInfo, actualRequest.getProjectBillingInfo()); 508 Assert.assertTrue( 509 channelProvider.isHeaderSent( 510 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 511 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 512 } 513 514 @Test updateProjectBillingInfoExceptionTest()515 public void updateProjectBillingInfoExceptionTest() throws Exception { 516 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 517 mockCloudBilling.addException(exception); 518 519 try { 520 String name = "name3373707"; 521 ProjectBillingInfo projectBillingInfo = ProjectBillingInfo.newBuilder().build(); 522 client.updateProjectBillingInfo(name, projectBillingInfo); 523 Assert.fail("No exception raised"); 524 } catch (InvalidArgumentException e) { 525 // Expected exception. 526 } 527 } 528 529 @Test getIamPolicyTest()530 public void getIamPolicyTest() throws Exception { 531 Policy expectedResponse = 532 Policy.newBuilder() 533 .setVersion(351608024) 534 .addAllBindings(new ArrayList<Binding>()) 535 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 536 .setEtag(ByteString.EMPTY) 537 .build(); 538 mockCloudBilling.addResponse(expectedResponse); 539 540 ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); 541 542 Policy actualResponse = client.getIamPolicy(resource); 543 Assert.assertEquals(expectedResponse, actualResponse); 544 545 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 546 Assert.assertEquals(1, actualRequests.size()); 547 GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); 548 549 Assert.assertEquals(resource.toString(), actualRequest.getResource()); 550 Assert.assertTrue( 551 channelProvider.isHeaderSent( 552 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 553 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 554 } 555 556 @Test getIamPolicyExceptionTest()557 public void getIamPolicyExceptionTest() throws Exception { 558 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 559 mockCloudBilling.addException(exception); 560 561 try { 562 ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); 563 client.getIamPolicy(resource); 564 Assert.fail("No exception raised"); 565 } catch (InvalidArgumentException e) { 566 // Expected exception. 567 } 568 } 569 570 @Test getIamPolicyTest2()571 public void getIamPolicyTest2() throws Exception { 572 Policy expectedResponse = 573 Policy.newBuilder() 574 .setVersion(351608024) 575 .addAllBindings(new ArrayList<Binding>()) 576 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 577 .setEtag(ByteString.EMPTY) 578 .build(); 579 mockCloudBilling.addResponse(expectedResponse); 580 581 String resource = "resource-341064690"; 582 583 Policy actualResponse = client.getIamPolicy(resource); 584 Assert.assertEquals(expectedResponse, actualResponse); 585 586 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 587 Assert.assertEquals(1, actualRequests.size()); 588 GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); 589 590 Assert.assertEquals(resource, actualRequest.getResource()); 591 Assert.assertTrue( 592 channelProvider.isHeaderSent( 593 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 594 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 595 } 596 597 @Test getIamPolicyExceptionTest2()598 public void getIamPolicyExceptionTest2() throws Exception { 599 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 600 mockCloudBilling.addException(exception); 601 602 try { 603 String resource = "resource-341064690"; 604 client.getIamPolicy(resource); 605 Assert.fail("No exception raised"); 606 } catch (InvalidArgumentException e) { 607 // Expected exception. 608 } 609 } 610 611 @Test setIamPolicyTest()612 public void setIamPolicyTest() throws Exception { 613 Policy expectedResponse = 614 Policy.newBuilder() 615 .setVersion(351608024) 616 .addAllBindings(new ArrayList<Binding>()) 617 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 618 .setEtag(ByteString.EMPTY) 619 .build(); 620 mockCloudBilling.addResponse(expectedResponse); 621 622 ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); 623 Policy policy = Policy.newBuilder().build(); 624 625 Policy actualResponse = client.setIamPolicy(resource, policy); 626 Assert.assertEquals(expectedResponse, actualResponse); 627 628 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 629 Assert.assertEquals(1, actualRequests.size()); 630 SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); 631 632 Assert.assertEquals(resource.toString(), actualRequest.getResource()); 633 Assert.assertEquals(policy, actualRequest.getPolicy()); 634 Assert.assertTrue( 635 channelProvider.isHeaderSent( 636 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 637 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 638 } 639 640 @Test setIamPolicyExceptionTest()641 public void setIamPolicyExceptionTest() throws Exception { 642 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 643 mockCloudBilling.addException(exception); 644 645 try { 646 ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); 647 Policy policy = Policy.newBuilder().build(); 648 client.setIamPolicy(resource, policy); 649 Assert.fail("No exception raised"); 650 } catch (InvalidArgumentException e) { 651 // Expected exception. 652 } 653 } 654 655 @Test setIamPolicyTest2()656 public void setIamPolicyTest2() throws Exception { 657 Policy expectedResponse = 658 Policy.newBuilder() 659 .setVersion(351608024) 660 .addAllBindings(new ArrayList<Binding>()) 661 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 662 .setEtag(ByteString.EMPTY) 663 .build(); 664 mockCloudBilling.addResponse(expectedResponse); 665 666 String resource = "resource-341064690"; 667 Policy policy = Policy.newBuilder().build(); 668 669 Policy actualResponse = client.setIamPolicy(resource, policy); 670 Assert.assertEquals(expectedResponse, actualResponse); 671 672 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 673 Assert.assertEquals(1, actualRequests.size()); 674 SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); 675 676 Assert.assertEquals(resource, actualRequest.getResource()); 677 Assert.assertEquals(policy, actualRequest.getPolicy()); 678 Assert.assertTrue( 679 channelProvider.isHeaderSent( 680 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 681 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 682 } 683 684 @Test setIamPolicyExceptionTest2()685 public void setIamPolicyExceptionTest2() throws Exception { 686 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 687 mockCloudBilling.addException(exception); 688 689 try { 690 String resource = "resource-341064690"; 691 Policy policy = Policy.newBuilder().build(); 692 client.setIamPolicy(resource, policy); 693 Assert.fail("No exception raised"); 694 } catch (InvalidArgumentException e) { 695 // Expected exception. 696 } 697 } 698 699 @Test testIamPermissionsTest()700 public void testIamPermissionsTest() throws Exception { 701 TestIamPermissionsResponse expectedResponse = 702 TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build(); 703 mockCloudBilling.addResponse(expectedResponse); 704 705 ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); 706 List<String> permissions = new ArrayList<>(); 707 708 TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); 709 Assert.assertEquals(expectedResponse, actualResponse); 710 711 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 712 Assert.assertEquals(1, actualRequests.size()); 713 TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); 714 715 Assert.assertEquals(resource.toString(), actualRequest.getResource()); 716 Assert.assertEquals(permissions, actualRequest.getPermissionsList()); 717 Assert.assertTrue( 718 channelProvider.isHeaderSent( 719 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 720 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 721 } 722 723 @Test testIamPermissionsExceptionTest()724 public void testIamPermissionsExceptionTest() throws Exception { 725 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 726 mockCloudBilling.addException(exception); 727 728 try { 729 ResourceName resource = BillingAccountName.of("[BILLING_ACCOUNT]"); 730 List<String> permissions = new ArrayList<>(); 731 client.testIamPermissions(resource, permissions); 732 Assert.fail("No exception raised"); 733 } catch (InvalidArgumentException e) { 734 // Expected exception. 735 } 736 } 737 738 @Test testIamPermissionsTest2()739 public void testIamPermissionsTest2() throws Exception { 740 TestIamPermissionsResponse expectedResponse = 741 TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build(); 742 mockCloudBilling.addResponse(expectedResponse); 743 744 String resource = "resource-341064690"; 745 List<String> permissions = new ArrayList<>(); 746 747 TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); 748 Assert.assertEquals(expectedResponse, actualResponse); 749 750 List<AbstractMessage> actualRequests = mockCloudBilling.getRequests(); 751 Assert.assertEquals(1, actualRequests.size()); 752 TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); 753 754 Assert.assertEquals(resource, actualRequest.getResource()); 755 Assert.assertEquals(permissions, actualRequest.getPermissionsList()); 756 Assert.assertTrue( 757 channelProvider.isHeaderSent( 758 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 759 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 760 } 761 762 @Test testIamPermissionsExceptionTest2()763 public void testIamPermissionsExceptionTest2() throws Exception { 764 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 765 mockCloudBilling.addException(exception); 766 767 try { 768 String resource = "resource-341064690"; 769 List<String> permissions = new ArrayList<>(); 770 client.testIamPermissions(resource, permissions); 771 Assert.fail("No exception raised"); 772 } catch (InvalidArgumentException e) { 773 // Expected exception. 774 } 775 } 776 } 777