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.asset.v1; 18 19 import static com.google.cloud.asset.v1.AssetServiceClient.AnalyzeOrgPoliciesPagedResponse; 20 import static com.google.cloud.asset.v1.AssetServiceClient.AnalyzeOrgPolicyGovernedAssetsPagedResponse; 21 import static com.google.cloud.asset.v1.AssetServiceClient.AnalyzeOrgPolicyGovernedContainersPagedResponse; 22 import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; 23 import static com.google.cloud.asset.v1.AssetServiceClient.ListSavedQueriesPagedResponse; 24 import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; 25 import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; 26 27 import com.google.api.gax.core.NoCredentialsProvider; 28 import com.google.api.gax.grpc.GaxGrpcProperties; 29 import com.google.api.gax.grpc.testing.LocalChannelProvider; 30 import com.google.api.gax.grpc.testing.MockGrpcService; 31 import com.google.api.gax.grpc.testing.MockServiceHelper; 32 import com.google.api.gax.rpc.ApiClientHeaderProvider; 33 import com.google.api.gax.rpc.InvalidArgumentException; 34 import com.google.api.gax.rpc.StatusCode; 35 import com.google.api.resourcenames.ResourceName; 36 import com.google.common.collect.Lists; 37 import com.google.longrunning.Operation; 38 import com.google.protobuf.AbstractMessage; 39 import com.google.protobuf.Any; 40 import com.google.protobuf.Duration; 41 import com.google.protobuf.Empty; 42 import com.google.protobuf.FieldMask; 43 import com.google.protobuf.Timestamp; 44 import com.google.type.Expr; 45 import io.grpc.StatusRuntimeException; 46 import java.io.IOException; 47 import java.util.ArrayList; 48 import java.util.Arrays; 49 import java.util.HashMap; 50 import java.util.List; 51 import java.util.UUID; 52 import java.util.concurrent.ExecutionException; 53 import javax.annotation.Generated; 54 import org.junit.After; 55 import org.junit.AfterClass; 56 import org.junit.Assert; 57 import org.junit.Before; 58 import org.junit.BeforeClass; 59 import org.junit.Test; 60 61 @Generated("by gapic-generator-java") 62 public class AssetServiceClientTest { 63 private static MockAssetService mockAssetService; 64 private static MockServiceHelper mockServiceHelper; 65 private LocalChannelProvider channelProvider; 66 private AssetServiceClient client; 67 68 @BeforeClass startStaticServer()69 public static void startStaticServer() { 70 mockAssetService = new MockAssetService(); 71 mockServiceHelper = 72 new MockServiceHelper( 73 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockAssetService)); 74 mockServiceHelper.start(); 75 } 76 77 @AfterClass stopServer()78 public static void stopServer() { 79 mockServiceHelper.stop(); 80 } 81 82 @Before setUp()83 public void setUp() throws IOException { 84 mockServiceHelper.reset(); 85 channelProvider = mockServiceHelper.createChannelProvider(); 86 AssetServiceSettings settings = 87 AssetServiceSettings.newBuilder() 88 .setTransportChannelProvider(channelProvider) 89 .setCredentialsProvider(NoCredentialsProvider.create()) 90 .build(); 91 client = AssetServiceClient.create(settings); 92 } 93 94 @After tearDown()95 public void tearDown() throws Exception { 96 client.close(); 97 } 98 99 @Test exportAssetsTest()100 public void exportAssetsTest() throws Exception { 101 ExportAssetsResponse expectedResponse = 102 ExportAssetsResponse.newBuilder() 103 .setReadTime(Timestamp.newBuilder().build()) 104 .setOutputConfig(OutputConfig.newBuilder().build()) 105 .setOutputResult(OutputResult.newBuilder().build()) 106 .build(); 107 Operation resultOperation = 108 Operation.newBuilder() 109 .setName("exportAssetsTest") 110 .setDone(true) 111 .setResponse(Any.pack(expectedResponse)) 112 .build(); 113 mockAssetService.addResponse(resultOperation); 114 115 ExportAssetsRequest request = 116 ExportAssetsRequest.newBuilder() 117 .setParent(FolderName.of("[FOLDER]").toString()) 118 .setReadTime(Timestamp.newBuilder().build()) 119 .addAllAssetTypes(new ArrayList<String>()) 120 .setContentType(ContentType.forNumber(0)) 121 .setOutputConfig(OutputConfig.newBuilder().build()) 122 .addAllRelationshipTypes(new ArrayList<String>()) 123 .build(); 124 125 ExportAssetsResponse actualResponse = client.exportAssetsAsync(request).get(); 126 Assert.assertEquals(expectedResponse, actualResponse); 127 128 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 129 Assert.assertEquals(1, actualRequests.size()); 130 ExportAssetsRequest actualRequest = ((ExportAssetsRequest) actualRequests.get(0)); 131 132 Assert.assertEquals(request.getParent(), actualRequest.getParent()); 133 Assert.assertEquals(request.getReadTime(), actualRequest.getReadTime()); 134 Assert.assertEquals(request.getAssetTypesList(), actualRequest.getAssetTypesList()); 135 Assert.assertEquals(request.getContentType(), actualRequest.getContentType()); 136 Assert.assertEquals(request.getOutputConfig(), actualRequest.getOutputConfig()); 137 Assert.assertEquals( 138 request.getRelationshipTypesList(), actualRequest.getRelationshipTypesList()); 139 Assert.assertTrue( 140 channelProvider.isHeaderSent( 141 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 142 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 143 } 144 145 @Test exportAssetsExceptionTest()146 public void exportAssetsExceptionTest() throws Exception { 147 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 148 mockAssetService.addException(exception); 149 150 try { 151 ExportAssetsRequest request = 152 ExportAssetsRequest.newBuilder() 153 .setParent(FolderName.of("[FOLDER]").toString()) 154 .setReadTime(Timestamp.newBuilder().build()) 155 .addAllAssetTypes(new ArrayList<String>()) 156 .setContentType(ContentType.forNumber(0)) 157 .setOutputConfig(OutputConfig.newBuilder().build()) 158 .addAllRelationshipTypes(new ArrayList<String>()) 159 .build(); 160 client.exportAssetsAsync(request).get(); 161 Assert.fail("No exception raised"); 162 } catch (ExecutionException e) { 163 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 164 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 165 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 166 } 167 } 168 169 @Test listAssetsTest()170 public void listAssetsTest() throws Exception { 171 Asset responsesElement = Asset.newBuilder().build(); 172 ListAssetsResponse expectedResponse = 173 ListAssetsResponse.newBuilder() 174 .setNextPageToken("") 175 .addAllAssets(Arrays.asList(responsesElement)) 176 .build(); 177 mockAssetService.addResponse(expectedResponse); 178 179 ResourceName parent = FolderName.of("[FOLDER]"); 180 181 ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); 182 183 List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 184 185 Assert.assertEquals(1, resources.size()); 186 Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0)); 187 188 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 189 Assert.assertEquals(1, actualRequests.size()); 190 ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0)); 191 192 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 193 Assert.assertTrue( 194 channelProvider.isHeaderSent( 195 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 196 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 197 } 198 199 @Test listAssetsExceptionTest()200 public void listAssetsExceptionTest() throws Exception { 201 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 202 mockAssetService.addException(exception); 203 204 try { 205 ResourceName parent = FolderName.of("[FOLDER]"); 206 client.listAssets(parent); 207 Assert.fail("No exception raised"); 208 } catch (InvalidArgumentException e) { 209 // Expected exception. 210 } 211 } 212 213 @Test listAssetsTest2()214 public void listAssetsTest2() throws Exception { 215 Asset responsesElement = Asset.newBuilder().build(); 216 ListAssetsResponse expectedResponse = 217 ListAssetsResponse.newBuilder() 218 .setNextPageToken("") 219 .addAllAssets(Arrays.asList(responsesElement)) 220 .build(); 221 mockAssetService.addResponse(expectedResponse); 222 223 String parent = "parent-995424086"; 224 225 ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); 226 227 List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 228 229 Assert.assertEquals(1, resources.size()); 230 Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0)); 231 232 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 233 Assert.assertEquals(1, actualRequests.size()); 234 ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0)); 235 236 Assert.assertEquals(parent, actualRequest.getParent()); 237 Assert.assertTrue( 238 channelProvider.isHeaderSent( 239 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 240 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 241 } 242 243 @Test listAssetsExceptionTest2()244 public void listAssetsExceptionTest2() throws Exception { 245 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 246 mockAssetService.addException(exception); 247 248 try { 249 String parent = "parent-995424086"; 250 client.listAssets(parent); 251 Assert.fail("No exception raised"); 252 } catch (InvalidArgumentException e) { 253 // Expected exception. 254 } 255 } 256 257 @Test batchGetAssetsHistoryTest()258 public void batchGetAssetsHistoryTest() throws Exception { 259 BatchGetAssetsHistoryResponse expectedResponse = 260 BatchGetAssetsHistoryResponse.newBuilder() 261 .addAllAssets(new ArrayList<TemporalAsset>()) 262 .build(); 263 mockAssetService.addResponse(expectedResponse); 264 265 BatchGetAssetsHistoryRequest request = 266 BatchGetAssetsHistoryRequest.newBuilder() 267 .setParent(FolderName.of("[FOLDER]").toString()) 268 .addAllAssetNames(new ArrayList<String>()) 269 .setContentType(ContentType.forNumber(0)) 270 .setReadTimeWindow(TimeWindow.newBuilder().build()) 271 .addAllRelationshipTypes(new ArrayList<String>()) 272 .build(); 273 274 BatchGetAssetsHistoryResponse actualResponse = client.batchGetAssetsHistory(request); 275 Assert.assertEquals(expectedResponse, actualResponse); 276 277 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 278 Assert.assertEquals(1, actualRequests.size()); 279 BatchGetAssetsHistoryRequest actualRequest = 280 ((BatchGetAssetsHistoryRequest) actualRequests.get(0)); 281 282 Assert.assertEquals(request.getParent(), actualRequest.getParent()); 283 Assert.assertEquals(request.getAssetNamesList(), actualRequest.getAssetNamesList()); 284 Assert.assertEquals(request.getContentType(), actualRequest.getContentType()); 285 Assert.assertEquals(request.getReadTimeWindow(), actualRequest.getReadTimeWindow()); 286 Assert.assertEquals( 287 request.getRelationshipTypesList(), actualRequest.getRelationshipTypesList()); 288 Assert.assertTrue( 289 channelProvider.isHeaderSent( 290 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 291 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 292 } 293 294 @Test batchGetAssetsHistoryExceptionTest()295 public void batchGetAssetsHistoryExceptionTest() throws Exception { 296 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 297 mockAssetService.addException(exception); 298 299 try { 300 BatchGetAssetsHistoryRequest request = 301 BatchGetAssetsHistoryRequest.newBuilder() 302 .setParent(FolderName.of("[FOLDER]").toString()) 303 .addAllAssetNames(new ArrayList<String>()) 304 .setContentType(ContentType.forNumber(0)) 305 .setReadTimeWindow(TimeWindow.newBuilder().build()) 306 .addAllRelationshipTypes(new ArrayList<String>()) 307 .build(); 308 client.batchGetAssetsHistory(request); 309 Assert.fail("No exception raised"); 310 } catch (InvalidArgumentException e) { 311 // Expected exception. 312 } 313 } 314 315 @Test createFeedTest()316 public void createFeedTest() throws Exception { 317 Feed expectedResponse = 318 Feed.newBuilder() 319 .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) 320 .addAllAssetNames(new ArrayList<String>()) 321 .addAllAssetTypes(new ArrayList<String>()) 322 .setContentType(ContentType.forNumber(0)) 323 .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) 324 .setCondition(Expr.newBuilder().build()) 325 .addAllRelationshipTypes(new ArrayList<String>()) 326 .build(); 327 mockAssetService.addResponse(expectedResponse); 328 329 String parent = "parent-995424086"; 330 331 Feed actualResponse = client.createFeed(parent); 332 Assert.assertEquals(expectedResponse, actualResponse); 333 334 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 335 Assert.assertEquals(1, actualRequests.size()); 336 CreateFeedRequest actualRequest = ((CreateFeedRequest) actualRequests.get(0)); 337 338 Assert.assertEquals(parent, actualRequest.getParent()); 339 Assert.assertTrue( 340 channelProvider.isHeaderSent( 341 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 342 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 343 } 344 345 @Test createFeedExceptionTest()346 public void createFeedExceptionTest() throws Exception { 347 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 348 mockAssetService.addException(exception); 349 350 try { 351 String parent = "parent-995424086"; 352 client.createFeed(parent); 353 Assert.fail("No exception raised"); 354 } catch (InvalidArgumentException e) { 355 // Expected exception. 356 } 357 } 358 359 @Test getFeedTest()360 public void getFeedTest() throws Exception { 361 Feed expectedResponse = 362 Feed.newBuilder() 363 .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) 364 .addAllAssetNames(new ArrayList<String>()) 365 .addAllAssetTypes(new ArrayList<String>()) 366 .setContentType(ContentType.forNumber(0)) 367 .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) 368 .setCondition(Expr.newBuilder().build()) 369 .addAllRelationshipTypes(new ArrayList<String>()) 370 .build(); 371 mockAssetService.addResponse(expectedResponse); 372 373 FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); 374 375 Feed actualResponse = client.getFeed(name); 376 Assert.assertEquals(expectedResponse, actualResponse); 377 378 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 379 Assert.assertEquals(1, actualRequests.size()); 380 GetFeedRequest actualRequest = ((GetFeedRequest) actualRequests.get(0)); 381 382 Assert.assertEquals(name.toString(), actualRequest.getName()); 383 Assert.assertTrue( 384 channelProvider.isHeaderSent( 385 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 386 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 387 } 388 389 @Test getFeedExceptionTest()390 public void getFeedExceptionTest() throws Exception { 391 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 392 mockAssetService.addException(exception); 393 394 try { 395 FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); 396 client.getFeed(name); 397 Assert.fail("No exception raised"); 398 } catch (InvalidArgumentException e) { 399 // Expected exception. 400 } 401 } 402 403 @Test getFeedTest2()404 public void getFeedTest2() throws Exception { 405 Feed expectedResponse = 406 Feed.newBuilder() 407 .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) 408 .addAllAssetNames(new ArrayList<String>()) 409 .addAllAssetTypes(new ArrayList<String>()) 410 .setContentType(ContentType.forNumber(0)) 411 .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) 412 .setCondition(Expr.newBuilder().build()) 413 .addAllRelationshipTypes(new ArrayList<String>()) 414 .build(); 415 mockAssetService.addResponse(expectedResponse); 416 417 String name = "name3373707"; 418 419 Feed actualResponse = client.getFeed(name); 420 Assert.assertEquals(expectedResponse, actualResponse); 421 422 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 423 Assert.assertEquals(1, actualRequests.size()); 424 GetFeedRequest actualRequest = ((GetFeedRequest) actualRequests.get(0)); 425 426 Assert.assertEquals(name, actualRequest.getName()); 427 Assert.assertTrue( 428 channelProvider.isHeaderSent( 429 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 430 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 431 } 432 433 @Test getFeedExceptionTest2()434 public void getFeedExceptionTest2() throws Exception { 435 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 436 mockAssetService.addException(exception); 437 438 try { 439 String name = "name3373707"; 440 client.getFeed(name); 441 Assert.fail("No exception raised"); 442 } catch (InvalidArgumentException e) { 443 // Expected exception. 444 } 445 } 446 447 @Test listFeedsTest()448 public void listFeedsTest() throws Exception { 449 ListFeedsResponse expectedResponse = 450 ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList<Feed>()).build(); 451 mockAssetService.addResponse(expectedResponse); 452 453 String parent = "parent-995424086"; 454 455 ListFeedsResponse actualResponse = client.listFeeds(parent); 456 Assert.assertEquals(expectedResponse, actualResponse); 457 458 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 459 Assert.assertEquals(1, actualRequests.size()); 460 ListFeedsRequest actualRequest = ((ListFeedsRequest) actualRequests.get(0)); 461 462 Assert.assertEquals(parent, actualRequest.getParent()); 463 Assert.assertTrue( 464 channelProvider.isHeaderSent( 465 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 466 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 467 } 468 469 @Test listFeedsExceptionTest()470 public void listFeedsExceptionTest() throws Exception { 471 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 472 mockAssetService.addException(exception); 473 474 try { 475 String parent = "parent-995424086"; 476 client.listFeeds(parent); 477 Assert.fail("No exception raised"); 478 } catch (InvalidArgumentException e) { 479 // Expected exception. 480 } 481 } 482 483 @Test updateFeedTest()484 public void updateFeedTest() throws Exception { 485 Feed expectedResponse = 486 Feed.newBuilder() 487 .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) 488 .addAllAssetNames(new ArrayList<String>()) 489 .addAllAssetTypes(new ArrayList<String>()) 490 .setContentType(ContentType.forNumber(0)) 491 .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) 492 .setCondition(Expr.newBuilder().build()) 493 .addAllRelationshipTypes(new ArrayList<String>()) 494 .build(); 495 mockAssetService.addResponse(expectedResponse); 496 497 Feed feed = Feed.newBuilder().build(); 498 499 Feed actualResponse = client.updateFeed(feed); 500 Assert.assertEquals(expectedResponse, actualResponse); 501 502 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 503 Assert.assertEquals(1, actualRequests.size()); 504 UpdateFeedRequest actualRequest = ((UpdateFeedRequest) actualRequests.get(0)); 505 506 Assert.assertEquals(feed, actualRequest.getFeed()); 507 Assert.assertTrue( 508 channelProvider.isHeaderSent( 509 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 510 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 511 } 512 513 @Test updateFeedExceptionTest()514 public void updateFeedExceptionTest() throws Exception { 515 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 516 mockAssetService.addException(exception); 517 518 try { 519 Feed feed = Feed.newBuilder().build(); 520 client.updateFeed(feed); 521 Assert.fail("No exception raised"); 522 } catch (InvalidArgumentException e) { 523 // Expected exception. 524 } 525 } 526 527 @Test deleteFeedTest()528 public void deleteFeedTest() throws Exception { 529 Empty expectedResponse = Empty.newBuilder().build(); 530 mockAssetService.addResponse(expectedResponse); 531 532 FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); 533 534 client.deleteFeed(name); 535 536 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 537 Assert.assertEquals(1, actualRequests.size()); 538 DeleteFeedRequest actualRequest = ((DeleteFeedRequest) actualRequests.get(0)); 539 540 Assert.assertEquals(name.toString(), actualRequest.getName()); 541 Assert.assertTrue( 542 channelProvider.isHeaderSent( 543 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 544 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 545 } 546 547 @Test deleteFeedExceptionTest()548 public void deleteFeedExceptionTest() throws Exception { 549 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 550 mockAssetService.addException(exception); 551 552 try { 553 FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); 554 client.deleteFeed(name); 555 Assert.fail("No exception raised"); 556 } catch (InvalidArgumentException e) { 557 // Expected exception. 558 } 559 } 560 561 @Test deleteFeedTest2()562 public void deleteFeedTest2() throws Exception { 563 Empty expectedResponse = Empty.newBuilder().build(); 564 mockAssetService.addResponse(expectedResponse); 565 566 String name = "name3373707"; 567 568 client.deleteFeed(name); 569 570 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 571 Assert.assertEquals(1, actualRequests.size()); 572 DeleteFeedRequest actualRequest = ((DeleteFeedRequest) actualRequests.get(0)); 573 574 Assert.assertEquals(name, actualRequest.getName()); 575 Assert.assertTrue( 576 channelProvider.isHeaderSent( 577 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 578 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 579 } 580 581 @Test deleteFeedExceptionTest2()582 public void deleteFeedExceptionTest2() throws Exception { 583 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 584 mockAssetService.addException(exception); 585 586 try { 587 String name = "name3373707"; 588 client.deleteFeed(name); 589 Assert.fail("No exception raised"); 590 } catch (InvalidArgumentException e) { 591 // Expected exception. 592 } 593 } 594 595 @Test searchAllResourcesTest()596 public void searchAllResourcesTest() throws Exception { 597 ResourceSearchResult responsesElement = ResourceSearchResult.newBuilder().build(); 598 SearchAllResourcesResponse expectedResponse = 599 SearchAllResourcesResponse.newBuilder() 600 .setNextPageToken("") 601 .addAllResults(Arrays.asList(responsesElement)) 602 .build(); 603 mockAssetService.addResponse(expectedResponse); 604 605 String scope = "scope109264468"; 606 String query = "query107944136"; 607 List<String> assetTypes = new ArrayList<>(); 608 609 SearchAllResourcesPagedResponse pagedListResponse = 610 client.searchAllResources(scope, query, assetTypes); 611 612 List<ResourceSearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 613 614 Assert.assertEquals(1, resources.size()); 615 Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); 616 617 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 618 Assert.assertEquals(1, actualRequests.size()); 619 SearchAllResourcesRequest actualRequest = ((SearchAllResourcesRequest) actualRequests.get(0)); 620 621 Assert.assertEquals(scope, actualRequest.getScope()); 622 Assert.assertEquals(query, actualRequest.getQuery()); 623 Assert.assertEquals(assetTypes, actualRequest.getAssetTypesList()); 624 Assert.assertTrue( 625 channelProvider.isHeaderSent( 626 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 627 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 628 } 629 630 @Test searchAllResourcesExceptionTest()631 public void searchAllResourcesExceptionTest() throws Exception { 632 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 633 mockAssetService.addException(exception); 634 635 try { 636 String scope = "scope109264468"; 637 String query = "query107944136"; 638 List<String> assetTypes = new ArrayList<>(); 639 client.searchAllResources(scope, query, assetTypes); 640 Assert.fail("No exception raised"); 641 } catch (InvalidArgumentException e) { 642 // Expected exception. 643 } 644 } 645 646 @Test searchAllIamPoliciesTest()647 public void searchAllIamPoliciesTest() throws Exception { 648 IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build(); 649 SearchAllIamPoliciesResponse expectedResponse = 650 SearchAllIamPoliciesResponse.newBuilder() 651 .setNextPageToken("") 652 .addAllResults(Arrays.asList(responsesElement)) 653 .build(); 654 mockAssetService.addResponse(expectedResponse); 655 656 String scope = "scope109264468"; 657 String query = "query107944136"; 658 659 SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query); 660 661 List<IamPolicySearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 662 663 Assert.assertEquals(1, resources.size()); 664 Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); 665 666 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 667 Assert.assertEquals(1, actualRequests.size()); 668 SearchAllIamPoliciesRequest actualRequest = 669 ((SearchAllIamPoliciesRequest) actualRequests.get(0)); 670 671 Assert.assertEquals(scope, actualRequest.getScope()); 672 Assert.assertEquals(query, actualRequest.getQuery()); 673 Assert.assertTrue( 674 channelProvider.isHeaderSent( 675 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 676 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 677 } 678 679 @Test searchAllIamPoliciesExceptionTest()680 public void searchAllIamPoliciesExceptionTest() throws Exception { 681 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 682 mockAssetService.addException(exception); 683 684 try { 685 String scope = "scope109264468"; 686 String query = "query107944136"; 687 client.searchAllIamPolicies(scope, query); 688 Assert.fail("No exception raised"); 689 } catch (InvalidArgumentException e) { 690 // Expected exception. 691 } 692 } 693 694 @Test analyzeIamPolicyTest()695 public void analyzeIamPolicyTest() throws Exception { 696 AnalyzeIamPolicyResponse expectedResponse = 697 AnalyzeIamPolicyResponse.newBuilder() 698 .setMainAnalysis(AnalyzeIamPolicyResponse.IamPolicyAnalysis.newBuilder().build()) 699 .addAllServiceAccountImpersonationAnalysis( 700 new ArrayList<AnalyzeIamPolicyResponse.IamPolicyAnalysis>()) 701 .setFullyExplored(true) 702 .build(); 703 mockAssetService.addResponse(expectedResponse); 704 705 AnalyzeIamPolicyRequest request = 706 AnalyzeIamPolicyRequest.newBuilder() 707 .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) 708 .setSavedAnalysisQuery("savedAnalysisQuery376058885") 709 .setExecutionTimeout(Duration.newBuilder().build()) 710 .build(); 711 712 AnalyzeIamPolicyResponse actualResponse = client.analyzeIamPolicy(request); 713 Assert.assertEquals(expectedResponse, actualResponse); 714 715 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 716 Assert.assertEquals(1, actualRequests.size()); 717 AnalyzeIamPolicyRequest actualRequest = ((AnalyzeIamPolicyRequest) actualRequests.get(0)); 718 719 Assert.assertEquals(request.getAnalysisQuery(), actualRequest.getAnalysisQuery()); 720 Assert.assertEquals(request.getSavedAnalysisQuery(), actualRequest.getSavedAnalysisQuery()); 721 Assert.assertEquals(request.getExecutionTimeout(), actualRequest.getExecutionTimeout()); 722 Assert.assertTrue( 723 channelProvider.isHeaderSent( 724 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 725 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 726 } 727 728 @Test analyzeIamPolicyExceptionTest()729 public void analyzeIamPolicyExceptionTest() throws Exception { 730 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 731 mockAssetService.addException(exception); 732 733 try { 734 AnalyzeIamPolicyRequest request = 735 AnalyzeIamPolicyRequest.newBuilder() 736 .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) 737 .setSavedAnalysisQuery("savedAnalysisQuery376058885") 738 .setExecutionTimeout(Duration.newBuilder().build()) 739 .build(); 740 client.analyzeIamPolicy(request); 741 Assert.fail("No exception raised"); 742 } catch (InvalidArgumentException e) { 743 // Expected exception. 744 } 745 } 746 747 @Test analyzeIamPolicyLongrunningTest()748 public void analyzeIamPolicyLongrunningTest() throws Exception { 749 AnalyzeIamPolicyLongrunningResponse expectedResponse = 750 AnalyzeIamPolicyLongrunningResponse.newBuilder().build(); 751 Operation resultOperation = 752 Operation.newBuilder() 753 .setName("analyzeIamPolicyLongrunningTest") 754 .setDone(true) 755 .setResponse(Any.pack(expectedResponse)) 756 .build(); 757 mockAssetService.addResponse(resultOperation); 758 759 AnalyzeIamPolicyLongrunningRequest request = 760 AnalyzeIamPolicyLongrunningRequest.newBuilder() 761 .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) 762 .setSavedAnalysisQuery("savedAnalysisQuery376058885") 763 .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) 764 .build(); 765 766 AnalyzeIamPolicyLongrunningResponse actualResponse = 767 client.analyzeIamPolicyLongrunningAsync(request).get(); 768 Assert.assertEquals(expectedResponse, actualResponse); 769 770 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 771 Assert.assertEquals(1, actualRequests.size()); 772 AnalyzeIamPolicyLongrunningRequest actualRequest = 773 ((AnalyzeIamPolicyLongrunningRequest) actualRequests.get(0)); 774 775 Assert.assertEquals(request.getAnalysisQuery(), actualRequest.getAnalysisQuery()); 776 Assert.assertEquals(request.getSavedAnalysisQuery(), actualRequest.getSavedAnalysisQuery()); 777 Assert.assertEquals(request.getOutputConfig(), actualRequest.getOutputConfig()); 778 Assert.assertTrue( 779 channelProvider.isHeaderSent( 780 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 781 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 782 } 783 784 @Test analyzeIamPolicyLongrunningExceptionTest()785 public void analyzeIamPolicyLongrunningExceptionTest() throws Exception { 786 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 787 mockAssetService.addException(exception); 788 789 try { 790 AnalyzeIamPolicyLongrunningRequest request = 791 AnalyzeIamPolicyLongrunningRequest.newBuilder() 792 .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) 793 .setSavedAnalysisQuery("savedAnalysisQuery376058885") 794 .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) 795 .build(); 796 client.analyzeIamPolicyLongrunningAsync(request).get(); 797 Assert.fail("No exception raised"); 798 } catch (ExecutionException e) { 799 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 800 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 801 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 802 } 803 } 804 805 @Test analyzeMoveTest()806 public void analyzeMoveTest() throws Exception { 807 AnalyzeMoveResponse expectedResponse = 808 AnalyzeMoveResponse.newBuilder().addAllMoveAnalysis(new ArrayList<MoveAnalysis>()).build(); 809 mockAssetService.addResponse(expectedResponse); 810 811 AnalyzeMoveRequest request = 812 AnalyzeMoveRequest.newBuilder() 813 .setResource("resource-341064690") 814 .setDestinationParent("destinationParent-1733659048") 815 .build(); 816 817 AnalyzeMoveResponse actualResponse = client.analyzeMove(request); 818 Assert.assertEquals(expectedResponse, actualResponse); 819 820 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 821 Assert.assertEquals(1, actualRequests.size()); 822 AnalyzeMoveRequest actualRequest = ((AnalyzeMoveRequest) actualRequests.get(0)); 823 824 Assert.assertEquals(request.getResource(), actualRequest.getResource()); 825 Assert.assertEquals(request.getDestinationParent(), actualRequest.getDestinationParent()); 826 Assert.assertEquals(request.getView(), actualRequest.getView()); 827 Assert.assertTrue( 828 channelProvider.isHeaderSent( 829 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 830 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 831 } 832 833 @Test analyzeMoveExceptionTest()834 public void analyzeMoveExceptionTest() throws Exception { 835 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 836 mockAssetService.addException(exception); 837 838 try { 839 AnalyzeMoveRequest request = 840 AnalyzeMoveRequest.newBuilder() 841 .setResource("resource-341064690") 842 .setDestinationParent("destinationParent-1733659048") 843 .build(); 844 client.analyzeMove(request); 845 Assert.fail("No exception raised"); 846 } catch (InvalidArgumentException e) { 847 // Expected exception. 848 } 849 } 850 851 @Test queryAssetsTest()852 public void queryAssetsTest() throws Exception { 853 QueryAssetsResponse expectedResponse = 854 QueryAssetsResponse.newBuilder() 855 .setJobReference("jobReference-2094880754") 856 .setDone(true) 857 .build(); 858 mockAssetService.addResponse(expectedResponse); 859 860 QueryAssetsRequest request = 861 QueryAssetsRequest.newBuilder() 862 .setParent(FolderName.of("[FOLDER]").toString()) 863 .setPageSize(883849137) 864 .setPageToken("pageToken873572522") 865 .setTimeout(Duration.newBuilder().build()) 866 .setOutputConfig(QueryAssetsOutputConfig.newBuilder().build()) 867 .build(); 868 869 QueryAssetsResponse actualResponse = client.queryAssets(request); 870 Assert.assertEquals(expectedResponse, actualResponse); 871 872 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 873 Assert.assertEquals(1, actualRequests.size()); 874 QueryAssetsRequest actualRequest = ((QueryAssetsRequest) actualRequests.get(0)); 875 876 Assert.assertEquals(request.getParent(), actualRequest.getParent()); 877 Assert.assertEquals(request.getStatement(), actualRequest.getStatement()); 878 Assert.assertEquals(request.getJobReference(), actualRequest.getJobReference()); 879 Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); 880 Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); 881 Assert.assertEquals(request.getTimeout(), actualRequest.getTimeout()); 882 Assert.assertEquals(request.getReadTimeWindow(), actualRequest.getReadTimeWindow()); 883 Assert.assertEquals(request.getReadTime(), actualRequest.getReadTime()); 884 Assert.assertEquals(request.getOutputConfig(), actualRequest.getOutputConfig()); 885 Assert.assertTrue( 886 channelProvider.isHeaderSent( 887 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 888 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 889 } 890 891 @Test queryAssetsExceptionTest()892 public void queryAssetsExceptionTest() throws Exception { 893 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 894 mockAssetService.addException(exception); 895 896 try { 897 QueryAssetsRequest request = 898 QueryAssetsRequest.newBuilder() 899 .setParent(FolderName.of("[FOLDER]").toString()) 900 .setPageSize(883849137) 901 .setPageToken("pageToken873572522") 902 .setTimeout(Duration.newBuilder().build()) 903 .setOutputConfig(QueryAssetsOutputConfig.newBuilder().build()) 904 .build(); 905 client.queryAssets(request); 906 Assert.fail("No exception raised"); 907 } catch (InvalidArgumentException e) { 908 // Expected exception. 909 } 910 } 911 912 @Test createSavedQueryTest()913 public void createSavedQueryTest() throws Exception { 914 SavedQuery expectedResponse = 915 SavedQuery.newBuilder() 916 .setName( 917 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 918 .setDescription("description-1724546052") 919 .setCreateTime(Timestamp.newBuilder().build()) 920 .setCreator("creator1028554796") 921 .setLastUpdateTime(Timestamp.newBuilder().build()) 922 .setLastUpdater("lastUpdater1649733971") 923 .putAllLabels(new HashMap<String, String>()) 924 .setContent(SavedQuery.QueryContent.newBuilder().build()) 925 .build(); 926 mockAssetService.addResponse(expectedResponse); 927 928 FolderName parent = FolderName.of("[FOLDER]"); 929 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 930 String savedQueryId = "savedQueryId378086268"; 931 932 SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); 933 Assert.assertEquals(expectedResponse, actualResponse); 934 935 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 936 Assert.assertEquals(1, actualRequests.size()); 937 CreateSavedQueryRequest actualRequest = ((CreateSavedQueryRequest) actualRequests.get(0)); 938 939 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 940 Assert.assertEquals(savedQuery, actualRequest.getSavedQuery()); 941 Assert.assertEquals(savedQueryId, actualRequest.getSavedQueryId()); 942 Assert.assertTrue( 943 channelProvider.isHeaderSent( 944 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 945 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 946 } 947 948 @Test createSavedQueryExceptionTest()949 public void createSavedQueryExceptionTest() throws Exception { 950 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 951 mockAssetService.addException(exception); 952 953 try { 954 FolderName parent = FolderName.of("[FOLDER]"); 955 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 956 String savedQueryId = "savedQueryId378086268"; 957 client.createSavedQuery(parent, savedQuery, savedQueryId); 958 Assert.fail("No exception raised"); 959 } catch (InvalidArgumentException e) { 960 // Expected exception. 961 } 962 } 963 964 @Test createSavedQueryTest2()965 public void createSavedQueryTest2() throws Exception { 966 SavedQuery expectedResponse = 967 SavedQuery.newBuilder() 968 .setName( 969 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 970 .setDescription("description-1724546052") 971 .setCreateTime(Timestamp.newBuilder().build()) 972 .setCreator("creator1028554796") 973 .setLastUpdateTime(Timestamp.newBuilder().build()) 974 .setLastUpdater("lastUpdater1649733971") 975 .putAllLabels(new HashMap<String, String>()) 976 .setContent(SavedQuery.QueryContent.newBuilder().build()) 977 .build(); 978 mockAssetService.addResponse(expectedResponse); 979 980 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 981 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 982 String savedQueryId = "savedQueryId378086268"; 983 984 SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); 985 Assert.assertEquals(expectedResponse, actualResponse); 986 987 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 988 Assert.assertEquals(1, actualRequests.size()); 989 CreateSavedQueryRequest actualRequest = ((CreateSavedQueryRequest) actualRequests.get(0)); 990 991 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 992 Assert.assertEquals(savedQuery, actualRequest.getSavedQuery()); 993 Assert.assertEquals(savedQueryId, actualRequest.getSavedQueryId()); 994 Assert.assertTrue( 995 channelProvider.isHeaderSent( 996 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 997 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 998 } 999 1000 @Test createSavedQueryExceptionTest2()1001 public void createSavedQueryExceptionTest2() throws Exception { 1002 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1003 mockAssetService.addException(exception); 1004 1005 try { 1006 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1007 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1008 String savedQueryId = "savedQueryId378086268"; 1009 client.createSavedQuery(parent, savedQuery, savedQueryId); 1010 Assert.fail("No exception raised"); 1011 } catch (InvalidArgumentException e) { 1012 // Expected exception. 1013 } 1014 } 1015 1016 @Test createSavedQueryTest3()1017 public void createSavedQueryTest3() throws Exception { 1018 SavedQuery expectedResponse = 1019 SavedQuery.newBuilder() 1020 .setName( 1021 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 1022 .setDescription("description-1724546052") 1023 .setCreateTime(Timestamp.newBuilder().build()) 1024 .setCreator("creator1028554796") 1025 .setLastUpdateTime(Timestamp.newBuilder().build()) 1026 .setLastUpdater("lastUpdater1649733971") 1027 .putAllLabels(new HashMap<String, String>()) 1028 .setContent(SavedQuery.QueryContent.newBuilder().build()) 1029 .build(); 1030 mockAssetService.addResponse(expectedResponse); 1031 1032 ProjectName parent = ProjectName.of("[PROJECT]"); 1033 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1034 String savedQueryId = "savedQueryId378086268"; 1035 1036 SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); 1037 Assert.assertEquals(expectedResponse, actualResponse); 1038 1039 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1040 Assert.assertEquals(1, actualRequests.size()); 1041 CreateSavedQueryRequest actualRequest = ((CreateSavedQueryRequest) actualRequests.get(0)); 1042 1043 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1044 Assert.assertEquals(savedQuery, actualRequest.getSavedQuery()); 1045 Assert.assertEquals(savedQueryId, actualRequest.getSavedQueryId()); 1046 Assert.assertTrue( 1047 channelProvider.isHeaderSent( 1048 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1049 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1050 } 1051 1052 @Test createSavedQueryExceptionTest3()1053 public void createSavedQueryExceptionTest3() throws Exception { 1054 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1055 mockAssetService.addException(exception); 1056 1057 try { 1058 ProjectName parent = ProjectName.of("[PROJECT]"); 1059 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1060 String savedQueryId = "savedQueryId378086268"; 1061 client.createSavedQuery(parent, savedQuery, savedQueryId); 1062 Assert.fail("No exception raised"); 1063 } catch (InvalidArgumentException e) { 1064 // Expected exception. 1065 } 1066 } 1067 1068 @Test createSavedQueryTest4()1069 public void createSavedQueryTest4() throws Exception { 1070 SavedQuery expectedResponse = 1071 SavedQuery.newBuilder() 1072 .setName( 1073 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 1074 .setDescription("description-1724546052") 1075 .setCreateTime(Timestamp.newBuilder().build()) 1076 .setCreator("creator1028554796") 1077 .setLastUpdateTime(Timestamp.newBuilder().build()) 1078 .setLastUpdater("lastUpdater1649733971") 1079 .putAllLabels(new HashMap<String, String>()) 1080 .setContent(SavedQuery.QueryContent.newBuilder().build()) 1081 .build(); 1082 mockAssetService.addResponse(expectedResponse); 1083 1084 String parent = "parent-995424086"; 1085 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1086 String savedQueryId = "savedQueryId378086268"; 1087 1088 SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); 1089 Assert.assertEquals(expectedResponse, actualResponse); 1090 1091 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1092 Assert.assertEquals(1, actualRequests.size()); 1093 CreateSavedQueryRequest actualRequest = ((CreateSavedQueryRequest) actualRequests.get(0)); 1094 1095 Assert.assertEquals(parent, actualRequest.getParent()); 1096 Assert.assertEquals(savedQuery, actualRequest.getSavedQuery()); 1097 Assert.assertEquals(savedQueryId, actualRequest.getSavedQueryId()); 1098 Assert.assertTrue( 1099 channelProvider.isHeaderSent( 1100 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1101 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1102 } 1103 1104 @Test createSavedQueryExceptionTest4()1105 public void createSavedQueryExceptionTest4() throws Exception { 1106 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1107 mockAssetService.addException(exception); 1108 1109 try { 1110 String parent = "parent-995424086"; 1111 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1112 String savedQueryId = "savedQueryId378086268"; 1113 client.createSavedQuery(parent, savedQuery, savedQueryId); 1114 Assert.fail("No exception raised"); 1115 } catch (InvalidArgumentException e) { 1116 // Expected exception. 1117 } 1118 } 1119 1120 @Test getSavedQueryTest()1121 public void getSavedQueryTest() throws Exception { 1122 SavedQuery expectedResponse = 1123 SavedQuery.newBuilder() 1124 .setName( 1125 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 1126 .setDescription("description-1724546052") 1127 .setCreateTime(Timestamp.newBuilder().build()) 1128 .setCreator("creator1028554796") 1129 .setLastUpdateTime(Timestamp.newBuilder().build()) 1130 .setLastUpdater("lastUpdater1649733971") 1131 .putAllLabels(new HashMap<String, String>()) 1132 .setContent(SavedQuery.QueryContent.newBuilder().build()) 1133 .build(); 1134 mockAssetService.addResponse(expectedResponse); 1135 1136 SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); 1137 1138 SavedQuery actualResponse = client.getSavedQuery(name); 1139 Assert.assertEquals(expectedResponse, actualResponse); 1140 1141 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1142 Assert.assertEquals(1, actualRequests.size()); 1143 GetSavedQueryRequest actualRequest = ((GetSavedQueryRequest) actualRequests.get(0)); 1144 1145 Assert.assertEquals(name.toString(), actualRequest.getName()); 1146 Assert.assertTrue( 1147 channelProvider.isHeaderSent( 1148 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1149 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1150 } 1151 1152 @Test getSavedQueryExceptionTest()1153 public void getSavedQueryExceptionTest() throws Exception { 1154 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1155 mockAssetService.addException(exception); 1156 1157 try { 1158 SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); 1159 client.getSavedQuery(name); 1160 Assert.fail("No exception raised"); 1161 } catch (InvalidArgumentException e) { 1162 // Expected exception. 1163 } 1164 } 1165 1166 @Test getSavedQueryTest2()1167 public void getSavedQueryTest2() throws Exception { 1168 SavedQuery expectedResponse = 1169 SavedQuery.newBuilder() 1170 .setName( 1171 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 1172 .setDescription("description-1724546052") 1173 .setCreateTime(Timestamp.newBuilder().build()) 1174 .setCreator("creator1028554796") 1175 .setLastUpdateTime(Timestamp.newBuilder().build()) 1176 .setLastUpdater("lastUpdater1649733971") 1177 .putAllLabels(new HashMap<String, String>()) 1178 .setContent(SavedQuery.QueryContent.newBuilder().build()) 1179 .build(); 1180 mockAssetService.addResponse(expectedResponse); 1181 1182 String name = "name3373707"; 1183 1184 SavedQuery actualResponse = client.getSavedQuery(name); 1185 Assert.assertEquals(expectedResponse, actualResponse); 1186 1187 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1188 Assert.assertEquals(1, actualRequests.size()); 1189 GetSavedQueryRequest actualRequest = ((GetSavedQueryRequest) actualRequests.get(0)); 1190 1191 Assert.assertEquals(name, actualRequest.getName()); 1192 Assert.assertTrue( 1193 channelProvider.isHeaderSent( 1194 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1195 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1196 } 1197 1198 @Test getSavedQueryExceptionTest2()1199 public void getSavedQueryExceptionTest2() throws Exception { 1200 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1201 mockAssetService.addException(exception); 1202 1203 try { 1204 String name = "name3373707"; 1205 client.getSavedQuery(name); 1206 Assert.fail("No exception raised"); 1207 } catch (InvalidArgumentException e) { 1208 // Expected exception. 1209 } 1210 } 1211 1212 @Test listSavedQueriesTest()1213 public void listSavedQueriesTest() throws Exception { 1214 SavedQuery responsesElement = SavedQuery.newBuilder().build(); 1215 ListSavedQueriesResponse expectedResponse = 1216 ListSavedQueriesResponse.newBuilder() 1217 .setNextPageToken("") 1218 .addAllSavedQueries(Arrays.asList(responsesElement)) 1219 .build(); 1220 mockAssetService.addResponse(expectedResponse); 1221 1222 FolderName parent = FolderName.of("[FOLDER]"); 1223 1224 ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); 1225 1226 List<SavedQuery> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1227 1228 Assert.assertEquals(1, resources.size()); 1229 Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); 1230 1231 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1232 Assert.assertEquals(1, actualRequests.size()); 1233 ListSavedQueriesRequest actualRequest = ((ListSavedQueriesRequest) actualRequests.get(0)); 1234 1235 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1236 Assert.assertTrue( 1237 channelProvider.isHeaderSent( 1238 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1239 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1240 } 1241 1242 @Test listSavedQueriesExceptionTest()1243 public void listSavedQueriesExceptionTest() throws Exception { 1244 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1245 mockAssetService.addException(exception); 1246 1247 try { 1248 FolderName parent = FolderName.of("[FOLDER]"); 1249 client.listSavedQueries(parent); 1250 Assert.fail("No exception raised"); 1251 } catch (InvalidArgumentException e) { 1252 // Expected exception. 1253 } 1254 } 1255 1256 @Test listSavedQueriesTest2()1257 public void listSavedQueriesTest2() throws Exception { 1258 SavedQuery responsesElement = SavedQuery.newBuilder().build(); 1259 ListSavedQueriesResponse expectedResponse = 1260 ListSavedQueriesResponse.newBuilder() 1261 .setNextPageToken("") 1262 .addAllSavedQueries(Arrays.asList(responsesElement)) 1263 .build(); 1264 mockAssetService.addResponse(expectedResponse); 1265 1266 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1267 1268 ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); 1269 1270 List<SavedQuery> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1271 1272 Assert.assertEquals(1, resources.size()); 1273 Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); 1274 1275 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1276 Assert.assertEquals(1, actualRequests.size()); 1277 ListSavedQueriesRequest actualRequest = ((ListSavedQueriesRequest) actualRequests.get(0)); 1278 1279 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1280 Assert.assertTrue( 1281 channelProvider.isHeaderSent( 1282 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1283 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1284 } 1285 1286 @Test listSavedQueriesExceptionTest2()1287 public void listSavedQueriesExceptionTest2() throws Exception { 1288 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1289 mockAssetService.addException(exception); 1290 1291 try { 1292 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1293 client.listSavedQueries(parent); 1294 Assert.fail("No exception raised"); 1295 } catch (InvalidArgumentException e) { 1296 // Expected exception. 1297 } 1298 } 1299 1300 @Test listSavedQueriesTest3()1301 public void listSavedQueriesTest3() throws Exception { 1302 SavedQuery responsesElement = SavedQuery.newBuilder().build(); 1303 ListSavedQueriesResponse expectedResponse = 1304 ListSavedQueriesResponse.newBuilder() 1305 .setNextPageToken("") 1306 .addAllSavedQueries(Arrays.asList(responsesElement)) 1307 .build(); 1308 mockAssetService.addResponse(expectedResponse); 1309 1310 ProjectName parent = ProjectName.of("[PROJECT]"); 1311 1312 ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); 1313 1314 List<SavedQuery> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1315 1316 Assert.assertEquals(1, resources.size()); 1317 Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); 1318 1319 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1320 Assert.assertEquals(1, actualRequests.size()); 1321 ListSavedQueriesRequest actualRequest = ((ListSavedQueriesRequest) actualRequests.get(0)); 1322 1323 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1324 Assert.assertTrue( 1325 channelProvider.isHeaderSent( 1326 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1327 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1328 } 1329 1330 @Test listSavedQueriesExceptionTest3()1331 public void listSavedQueriesExceptionTest3() throws Exception { 1332 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1333 mockAssetService.addException(exception); 1334 1335 try { 1336 ProjectName parent = ProjectName.of("[PROJECT]"); 1337 client.listSavedQueries(parent); 1338 Assert.fail("No exception raised"); 1339 } catch (InvalidArgumentException e) { 1340 // Expected exception. 1341 } 1342 } 1343 1344 @Test listSavedQueriesTest4()1345 public void listSavedQueriesTest4() throws Exception { 1346 SavedQuery responsesElement = SavedQuery.newBuilder().build(); 1347 ListSavedQueriesResponse expectedResponse = 1348 ListSavedQueriesResponse.newBuilder() 1349 .setNextPageToken("") 1350 .addAllSavedQueries(Arrays.asList(responsesElement)) 1351 .build(); 1352 mockAssetService.addResponse(expectedResponse); 1353 1354 String parent = "parent-995424086"; 1355 1356 ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); 1357 1358 List<SavedQuery> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1359 1360 Assert.assertEquals(1, resources.size()); 1361 Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); 1362 1363 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1364 Assert.assertEquals(1, actualRequests.size()); 1365 ListSavedQueriesRequest actualRequest = ((ListSavedQueriesRequest) actualRequests.get(0)); 1366 1367 Assert.assertEquals(parent, actualRequest.getParent()); 1368 Assert.assertTrue( 1369 channelProvider.isHeaderSent( 1370 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1371 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1372 } 1373 1374 @Test listSavedQueriesExceptionTest4()1375 public void listSavedQueriesExceptionTest4() throws Exception { 1376 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1377 mockAssetService.addException(exception); 1378 1379 try { 1380 String parent = "parent-995424086"; 1381 client.listSavedQueries(parent); 1382 Assert.fail("No exception raised"); 1383 } catch (InvalidArgumentException e) { 1384 // Expected exception. 1385 } 1386 } 1387 1388 @Test updateSavedQueryTest()1389 public void updateSavedQueryTest() throws Exception { 1390 SavedQuery expectedResponse = 1391 SavedQuery.newBuilder() 1392 .setName( 1393 SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) 1394 .setDescription("description-1724546052") 1395 .setCreateTime(Timestamp.newBuilder().build()) 1396 .setCreator("creator1028554796") 1397 .setLastUpdateTime(Timestamp.newBuilder().build()) 1398 .setLastUpdater("lastUpdater1649733971") 1399 .putAllLabels(new HashMap<String, String>()) 1400 .setContent(SavedQuery.QueryContent.newBuilder().build()) 1401 .build(); 1402 mockAssetService.addResponse(expectedResponse); 1403 1404 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1405 FieldMask updateMask = FieldMask.newBuilder().build(); 1406 1407 SavedQuery actualResponse = client.updateSavedQuery(savedQuery, updateMask); 1408 Assert.assertEquals(expectedResponse, actualResponse); 1409 1410 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1411 Assert.assertEquals(1, actualRequests.size()); 1412 UpdateSavedQueryRequest actualRequest = ((UpdateSavedQueryRequest) actualRequests.get(0)); 1413 1414 Assert.assertEquals(savedQuery, actualRequest.getSavedQuery()); 1415 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 1416 Assert.assertTrue( 1417 channelProvider.isHeaderSent( 1418 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1419 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1420 } 1421 1422 @Test updateSavedQueryExceptionTest()1423 public void updateSavedQueryExceptionTest() throws Exception { 1424 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1425 mockAssetService.addException(exception); 1426 1427 try { 1428 SavedQuery savedQuery = SavedQuery.newBuilder().build(); 1429 FieldMask updateMask = FieldMask.newBuilder().build(); 1430 client.updateSavedQuery(savedQuery, updateMask); 1431 Assert.fail("No exception raised"); 1432 } catch (InvalidArgumentException e) { 1433 // Expected exception. 1434 } 1435 } 1436 1437 @Test deleteSavedQueryTest()1438 public void deleteSavedQueryTest() throws Exception { 1439 Empty expectedResponse = Empty.newBuilder().build(); 1440 mockAssetService.addResponse(expectedResponse); 1441 1442 SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); 1443 1444 client.deleteSavedQuery(name); 1445 1446 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1447 Assert.assertEquals(1, actualRequests.size()); 1448 DeleteSavedQueryRequest actualRequest = ((DeleteSavedQueryRequest) actualRequests.get(0)); 1449 1450 Assert.assertEquals(name.toString(), actualRequest.getName()); 1451 Assert.assertTrue( 1452 channelProvider.isHeaderSent( 1453 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1454 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1455 } 1456 1457 @Test deleteSavedQueryExceptionTest()1458 public void deleteSavedQueryExceptionTest() throws Exception { 1459 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1460 mockAssetService.addException(exception); 1461 1462 try { 1463 SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); 1464 client.deleteSavedQuery(name); 1465 Assert.fail("No exception raised"); 1466 } catch (InvalidArgumentException e) { 1467 // Expected exception. 1468 } 1469 } 1470 1471 @Test deleteSavedQueryTest2()1472 public void deleteSavedQueryTest2() throws Exception { 1473 Empty expectedResponse = Empty.newBuilder().build(); 1474 mockAssetService.addResponse(expectedResponse); 1475 1476 String name = "name3373707"; 1477 1478 client.deleteSavedQuery(name); 1479 1480 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1481 Assert.assertEquals(1, actualRequests.size()); 1482 DeleteSavedQueryRequest actualRequest = ((DeleteSavedQueryRequest) actualRequests.get(0)); 1483 1484 Assert.assertEquals(name, actualRequest.getName()); 1485 Assert.assertTrue( 1486 channelProvider.isHeaderSent( 1487 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1488 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1489 } 1490 1491 @Test deleteSavedQueryExceptionTest2()1492 public void deleteSavedQueryExceptionTest2() throws Exception { 1493 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1494 mockAssetService.addException(exception); 1495 1496 try { 1497 String name = "name3373707"; 1498 client.deleteSavedQuery(name); 1499 Assert.fail("No exception raised"); 1500 } catch (InvalidArgumentException e) { 1501 // Expected exception. 1502 } 1503 } 1504 1505 @Test batchGetEffectiveIamPoliciesTest()1506 public void batchGetEffectiveIamPoliciesTest() throws Exception { 1507 BatchGetEffectiveIamPoliciesResponse expectedResponse = 1508 BatchGetEffectiveIamPoliciesResponse.newBuilder() 1509 .addAllPolicyResults( 1510 new ArrayList<BatchGetEffectiveIamPoliciesResponse.EffectiveIamPolicy>()) 1511 .build(); 1512 mockAssetService.addResponse(expectedResponse); 1513 1514 BatchGetEffectiveIamPoliciesRequest request = 1515 BatchGetEffectiveIamPoliciesRequest.newBuilder() 1516 .setScope(FolderName.of("[FOLDER]").toString()) 1517 .addAllNames(new ArrayList<String>()) 1518 .build(); 1519 1520 BatchGetEffectiveIamPoliciesResponse actualResponse = 1521 client.batchGetEffectiveIamPolicies(request); 1522 Assert.assertEquals(expectedResponse, actualResponse); 1523 1524 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1525 Assert.assertEquals(1, actualRequests.size()); 1526 BatchGetEffectiveIamPoliciesRequest actualRequest = 1527 ((BatchGetEffectiveIamPoliciesRequest) actualRequests.get(0)); 1528 1529 Assert.assertEquals(request.getScope(), actualRequest.getScope()); 1530 Assert.assertEquals(request.getNamesList(), actualRequest.getNamesList()); 1531 Assert.assertTrue( 1532 channelProvider.isHeaderSent( 1533 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1534 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1535 } 1536 1537 @Test batchGetEffectiveIamPoliciesExceptionTest()1538 public void batchGetEffectiveIamPoliciesExceptionTest() throws Exception { 1539 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1540 mockAssetService.addException(exception); 1541 1542 try { 1543 BatchGetEffectiveIamPoliciesRequest request = 1544 BatchGetEffectiveIamPoliciesRequest.newBuilder() 1545 .setScope(FolderName.of("[FOLDER]").toString()) 1546 .addAllNames(new ArrayList<String>()) 1547 .build(); 1548 client.batchGetEffectiveIamPolicies(request); 1549 Assert.fail("No exception raised"); 1550 } catch (InvalidArgumentException e) { 1551 // Expected exception. 1552 } 1553 } 1554 1555 @Test analyzeOrgPoliciesTest()1556 public void analyzeOrgPoliciesTest() throws Exception { 1557 AnalyzeOrgPoliciesResponse.OrgPolicyResult responsesElement = 1558 AnalyzeOrgPoliciesResponse.OrgPolicyResult.newBuilder().build(); 1559 AnalyzeOrgPoliciesResponse expectedResponse = 1560 AnalyzeOrgPoliciesResponse.newBuilder() 1561 .setNextPageToken("") 1562 .addAllOrgPolicyResults(Arrays.asList(responsesElement)) 1563 .build(); 1564 mockAssetService.addResponse(expectedResponse); 1565 1566 String scope = "scope109264468"; 1567 String constraint = "constraint-190376483"; 1568 String filter = "filter-1274492040"; 1569 1570 AnalyzeOrgPoliciesPagedResponse pagedListResponse = 1571 client.analyzeOrgPolicies(scope, constraint, filter); 1572 1573 List<AnalyzeOrgPoliciesResponse.OrgPolicyResult> resources = 1574 Lists.newArrayList(pagedListResponse.iterateAll()); 1575 1576 Assert.assertEquals(1, resources.size()); 1577 Assert.assertEquals(expectedResponse.getOrgPolicyResultsList().get(0), resources.get(0)); 1578 1579 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1580 Assert.assertEquals(1, actualRequests.size()); 1581 AnalyzeOrgPoliciesRequest actualRequest = ((AnalyzeOrgPoliciesRequest) actualRequests.get(0)); 1582 1583 Assert.assertEquals(scope, actualRequest.getScope()); 1584 Assert.assertEquals(constraint, actualRequest.getConstraint()); 1585 Assert.assertEquals(filter, actualRequest.getFilter()); 1586 Assert.assertTrue( 1587 channelProvider.isHeaderSent( 1588 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1589 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1590 } 1591 1592 @Test analyzeOrgPoliciesExceptionTest()1593 public void analyzeOrgPoliciesExceptionTest() throws Exception { 1594 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1595 mockAssetService.addException(exception); 1596 1597 try { 1598 String scope = "scope109264468"; 1599 String constraint = "constraint-190376483"; 1600 String filter = "filter-1274492040"; 1601 client.analyzeOrgPolicies(scope, constraint, filter); 1602 Assert.fail("No exception raised"); 1603 } catch (InvalidArgumentException e) { 1604 // Expected exception. 1605 } 1606 } 1607 1608 @Test analyzeOrgPolicyGovernedContainersTest()1609 public void analyzeOrgPolicyGovernedContainersTest() throws Exception { 1610 AnalyzeOrgPolicyGovernedContainersResponse.GovernedContainer responsesElement = 1611 AnalyzeOrgPolicyGovernedContainersResponse.GovernedContainer.newBuilder().build(); 1612 AnalyzeOrgPolicyGovernedContainersResponse expectedResponse = 1613 AnalyzeOrgPolicyGovernedContainersResponse.newBuilder() 1614 .setNextPageToken("") 1615 .addAllGovernedContainers(Arrays.asList(responsesElement)) 1616 .build(); 1617 mockAssetService.addResponse(expectedResponse); 1618 1619 String scope = "scope109264468"; 1620 String constraint = "constraint-190376483"; 1621 String filter = "filter-1274492040"; 1622 1623 AnalyzeOrgPolicyGovernedContainersPagedResponse pagedListResponse = 1624 client.analyzeOrgPolicyGovernedContainers(scope, constraint, filter); 1625 1626 List<AnalyzeOrgPolicyGovernedContainersResponse.GovernedContainer> resources = 1627 Lists.newArrayList(pagedListResponse.iterateAll()); 1628 1629 Assert.assertEquals(1, resources.size()); 1630 Assert.assertEquals(expectedResponse.getGovernedContainersList().get(0), resources.get(0)); 1631 1632 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1633 Assert.assertEquals(1, actualRequests.size()); 1634 AnalyzeOrgPolicyGovernedContainersRequest actualRequest = 1635 ((AnalyzeOrgPolicyGovernedContainersRequest) actualRequests.get(0)); 1636 1637 Assert.assertEquals(scope, actualRequest.getScope()); 1638 Assert.assertEquals(constraint, actualRequest.getConstraint()); 1639 Assert.assertEquals(filter, actualRequest.getFilter()); 1640 Assert.assertTrue( 1641 channelProvider.isHeaderSent( 1642 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1643 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1644 } 1645 1646 @Test analyzeOrgPolicyGovernedContainersExceptionTest()1647 public void analyzeOrgPolicyGovernedContainersExceptionTest() throws Exception { 1648 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1649 mockAssetService.addException(exception); 1650 1651 try { 1652 String scope = "scope109264468"; 1653 String constraint = "constraint-190376483"; 1654 String filter = "filter-1274492040"; 1655 client.analyzeOrgPolicyGovernedContainers(scope, constraint, filter); 1656 Assert.fail("No exception raised"); 1657 } catch (InvalidArgumentException e) { 1658 // Expected exception. 1659 } 1660 } 1661 1662 @Test analyzeOrgPolicyGovernedAssetsTest()1663 public void analyzeOrgPolicyGovernedAssetsTest() throws Exception { 1664 AnalyzeOrgPolicyGovernedAssetsResponse.GovernedAsset responsesElement = 1665 AnalyzeOrgPolicyGovernedAssetsResponse.GovernedAsset.newBuilder().build(); 1666 AnalyzeOrgPolicyGovernedAssetsResponse expectedResponse = 1667 AnalyzeOrgPolicyGovernedAssetsResponse.newBuilder() 1668 .setNextPageToken("") 1669 .addAllGovernedAssets(Arrays.asList(responsesElement)) 1670 .build(); 1671 mockAssetService.addResponse(expectedResponse); 1672 1673 String scope = "scope109264468"; 1674 String constraint = "constraint-190376483"; 1675 String filter = "filter-1274492040"; 1676 1677 AnalyzeOrgPolicyGovernedAssetsPagedResponse pagedListResponse = 1678 client.analyzeOrgPolicyGovernedAssets(scope, constraint, filter); 1679 1680 List<AnalyzeOrgPolicyGovernedAssetsResponse.GovernedAsset> resources = 1681 Lists.newArrayList(pagedListResponse.iterateAll()); 1682 1683 Assert.assertEquals(1, resources.size()); 1684 Assert.assertEquals(expectedResponse.getGovernedAssetsList().get(0), resources.get(0)); 1685 1686 List<AbstractMessage> actualRequests = mockAssetService.getRequests(); 1687 Assert.assertEquals(1, actualRequests.size()); 1688 AnalyzeOrgPolicyGovernedAssetsRequest actualRequest = 1689 ((AnalyzeOrgPolicyGovernedAssetsRequest) actualRequests.get(0)); 1690 1691 Assert.assertEquals(scope, actualRequest.getScope()); 1692 Assert.assertEquals(constraint, actualRequest.getConstraint()); 1693 Assert.assertEquals(filter, actualRequest.getFilter()); 1694 Assert.assertTrue( 1695 channelProvider.isHeaderSent( 1696 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1697 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1698 } 1699 1700 @Test analyzeOrgPolicyGovernedAssetsExceptionTest()1701 public void analyzeOrgPolicyGovernedAssetsExceptionTest() throws Exception { 1702 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1703 mockAssetService.addException(exception); 1704 1705 try { 1706 String scope = "scope109264468"; 1707 String constraint = "constraint-190376483"; 1708 String filter = "filter-1274492040"; 1709 client.analyzeOrgPolicyGovernedAssets(scope, constraint, filter); 1710 Assert.fail("No exception raised"); 1711 } catch (InvalidArgumentException e) { 1712 // Expected exception. 1713 } 1714 } 1715 } 1716