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.securitycenter.v1p1beta1; 18 19 import static com.google.cloud.securitycenter.v1p1beta1.SecurityCenterClient.GroupAssetsPagedResponse; 20 import static com.google.cloud.securitycenter.v1p1beta1.SecurityCenterClient.GroupFindingsPagedResponse; 21 import static com.google.cloud.securitycenter.v1p1beta1.SecurityCenterClient.ListAssetsPagedResponse; 22 import static com.google.cloud.securitycenter.v1p1beta1.SecurityCenterClient.ListFindingsPagedResponse; 23 import static com.google.cloud.securitycenter.v1p1beta1.SecurityCenterClient.ListNotificationConfigsPagedResponse; 24 import static com.google.cloud.securitycenter.v1p1beta1.SecurityCenterClient.ListSourcesPagedResponse; 25 26 import com.google.api.gax.core.NoCredentialsProvider; 27 import com.google.api.gax.httpjson.GaxHttpJsonProperties; 28 import com.google.api.gax.httpjson.testing.MockHttpService; 29 import com.google.api.gax.rpc.ApiClientHeaderProvider; 30 import com.google.api.gax.rpc.ApiException; 31 import com.google.api.gax.rpc.ApiExceptionFactory; 32 import com.google.api.gax.rpc.InvalidArgumentException; 33 import com.google.api.gax.rpc.StatusCode; 34 import com.google.api.gax.rpc.testing.FakeStatusCode; 35 import com.google.api.resourcenames.ResourceName; 36 import com.google.cloud.securitycenter.v1p1beta1.stub.HttpJsonSecurityCenterStub; 37 import com.google.common.collect.Lists; 38 import com.google.iam.v1.AuditConfig; 39 import com.google.iam.v1.Binding; 40 import com.google.iam.v1.Policy; 41 import com.google.iam.v1.TestIamPermissionsResponse; 42 import com.google.longrunning.Operation; 43 import com.google.protobuf.Any; 44 import com.google.protobuf.ByteString; 45 import com.google.protobuf.Duration; 46 import com.google.protobuf.Empty; 47 import com.google.protobuf.FieldMask; 48 import com.google.protobuf.Timestamp; 49 import com.google.protobuf.Value; 50 import java.io.IOException; 51 import java.util.ArrayList; 52 import java.util.Arrays; 53 import java.util.HashMap; 54 import java.util.List; 55 import java.util.concurrent.ExecutionException; 56 import javax.annotation.Generated; 57 import org.junit.After; 58 import org.junit.AfterClass; 59 import org.junit.Assert; 60 import org.junit.Before; 61 import org.junit.BeforeClass; 62 import org.junit.Test; 63 64 @Generated("by gapic-generator-java") 65 public class SecurityCenterClientHttpJsonTest { 66 private static MockHttpService mockService; 67 private static SecurityCenterClient client; 68 69 @BeforeClass startStaticServer()70 public static void startStaticServer() throws IOException { 71 mockService = 72 new MockHttpService( 73 HttpJsonSecurityCenterStub.getMethodDescriptors(), 74 SecurityCenterSettings.getDefaultEndpoint()); 75 SecurityCenterSettings settings = 76 SecurityCenterSettings.newHttpJsonBuilder() 77 .setTransportChannelProvider( 78 SecurityCenterSettings.defaultHttpJsonTransportProviderBuilder() 79 .setHttpTransport(mockService) 80 .build()) 81 .setCredentialsProvider(NoCredentialsProvider.create()) 82 .build(); 83 client = SecurityCenterClient.create(settings); 84 } 85 86 @AfterClass stopServer()87 public static void stopServer() { 88 client.close(); 89 } 90 91 @Before setUp()92 public void setUp() {} 93 94 @After tearDown()95 public void tearDown() throws Exception { 96 mockService.reset(); 97 } 98 99 @Test createSourceTest()100 public void createSourceTest() throws Exception { 101 Source expectedResponse = 102 Source.newBuilder() 103 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 104 .setDisplayName("displayName1714148973") 105 .setDescription("description-1724546052") 106 .setCanonicalName("canonicalName2122381727") 107 .build(); 108 mockService.addResponse(expectedResponse); 109 110 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 111 Source source = Source.newBuilder().build(); 112 113 Source actualResponse = client.createSource(parent, source); 114 Assert.assertEquals(expectedResponse, actualResponse); 115 116 List<String> actualRequests = mockService.getRequestPaths(); 117 Assert.assertEquals(1, actualRequests.size()); 118 119 String apiClientHeaderKey = 120 mockService 121 .getRequestHeaders() 122 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 123 .iterator() 124 .next(); 125 Assert.assertTrue( 126 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 127 .matcher(apiClientHeaderKey) 128 .matches()); 129 } 130 131 @Test createSourceExceptionTest()132 public void createSourceExceptionTest() throws Exception { 133 ApiException exception = 134 ApiExceptionFactory.createException( 135 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 136 mockService.addException(exception); 137 138 try { 139 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 140 Source source = Source.newBuilder().build(); 141 client.createSource(parent, source); 142 Assert.fail("No exception raised"); 143 } catch (InvalidArgumentException e) { 144 // Expected exception. 145 } 146 } 147 148 @Test createSourceTest2()149 public void createSourceTest2() throws Exception { 150 Source expectedResponse = 151 Source.newBuilder() 152 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 153 .setDisplayName("displayName1714148973") 154 .setDescription("description-1724546052") 155 .setCanonicalName("canonicalName2122381727") 156 .build(); 157 mockService.addResponse(expectedResponse); 158 159 String parent = "organizations/organization-8287"; 160 Source source = Source.newBuilder().build(); 161 162 Source actualResponse = client.createSource(parent, source); 163 Assert.assertEquals(expectedResponse, actualResponse); 164 165 List<String> actualRequests = mockService.getRequestPaths(); 166 Assert.assertEquals(1, actualRequests.size()); 167 168 String apiClientHeaderKey = 169 mockService 170 .getRequestHeaders() 171 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 172 .iterator() 173 .next(); 174 Assert.assertTrue( 175 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 176 .matcher(apiClientHeaderKey) 177 .matches()); 178 } 179 180 @Test createSourceExceptionTest2()181 public void createSourceExceptionTest2() throws Exception { 182 ApiException exception = 183 ApiExceptionFactory.createException( 184 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 185 mockService.addException(exception); 186 187 try { 188 String parent = "organizations/organization-8287"; 189 Source source = Source.newBuilder().build(); 190 client.createSource(parent, source); 191 Assert.fail("No exception raised"); 192 } catch (InvalidArgumentException e) { 193 // Expected exception. 194 } 195 } 196 197 @Test createFindingTest()198 public void createFindingTest() throws Exception { 199 Finding expectedResponse = 200 Finding.newBuilder() 201 .setName( 202 FindingName.ofOrganizationSourceFindingName( 203 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 204 .toString()) 205 .setParent("parent-995424086") 206 .setResourceName("resourceName-384566343") 207 .setCategory("category50511102") 208 .setExternalUri("externalUri-1153085023") 209 .putAllSourceProperties(new HashMap<String, Value>()) 210 .setSecurityMarks(SecurityMarks.newBuilder().build()) 211 .setEventTime(Timestamp.newBuilder().build()) 212 .setCreateTime(Timestamp.newBuilder().build()) 213 .setCanonicalName("canonicalName2122381727") 214 .build(); 215 mockService.addResponse(expectedResponse); 216 217 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 218 Finding finding = Finding.newBuilder().build(); 219 String findingId = "findingId439150212"; 220 221 Finding actualResponse = client.createFinding(parent, finding, findingId); 222 Assert.assertEquals(expectedResponse, actualResponse); 223 224 List<String> actualRequests = mockService.getRequestPaths(); 225 Assert.assertEquals(1, actualRequests.size()); 226 227 String apiClientHeaderKey = 228 mockService 229 .getRequestHeaders() 230 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 231 .iterator() 232 .next(); 233 Assert.assertTrue( 234 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 235 .matcher(apiClientHeaderKey) 236 .matches()); 237 } 238 239 @Test createFindingExceptionTest()240 public void createFindingExceptionTest() throws Exception { 241 ApiException exception = 242 ApiExceptionFactory.createException( 243 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 244 mockService.addException(exception); 245 246 try { 247 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 248 Finding finding = Finding.newBuilder().build(); 249 String findingId = "findingId439150212"; 250 client.createFinding(parent, finding, findingId); 251 Assert.fail("No exception raised"); 252 } catch (InvalidArgumentException e) { 253 // Expected exception. 254 } 255 } 256 257 @Test createFindingTest2()258 public void createFindingTest2() throws Exception { 259 Finding expectedResponse = 260 Finding.newBuilder() 261 .setName( 262 FindingName.ofOrganizationSourceFindingName( 263 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 264 .toString()) 265 .setParent("parent-995424086") 266 .setResourceName("resourceName-384566343") 267 .setCategory("category50511102") 268 .setExternalUri("externalUri-1153085023") 269 .putAllSourceProperties(new HashMap<String, Value>()) 270 .setSecurityMarks(SecurityMarks.newBuilder().build()) 271 .setEventTime(Timestamp.newBuilder().build()) 272 .setCreateTime(Timestamp.newBuilder().build()) 273 .setCanonicalName("canonicalName2122381727") 274 .build(); 275 mockService.addResponse(expectedResponse); 276 277 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 278 String findingId = "findingId439150212"; 279 Finding finding = Finding.newBuilder().build(); 280 281 Finding actualResponse = client.createFinding(parent, findingId, finding); 282 Assert.assertEquals(expectedResponse, actualResponse); 283 284 List<String> actualRequests = mockService.getRequestPaths(); 285 Assert.assertEquals(1, actualRequests.size()); 286 287 String apiClientHeaderKey = 288 mockService 289 .getRequestHeaders() 290 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 291 .iterator() 292 .next(); 293 Assert.assertTrue( 294 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 295 .matcher(apiClientHeaderKey) 296 .matches()); 297 } 298 299 @Test createFindingExceptionTest2()300 public void createFindingExceptionTest2() throws Exception { 301 ApiException exception = 302 ApiExceptionFactory.createException( 303 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 304 mockService.addException(exception); 305 306 try { 307 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 308 String findingId = "findingId439150212"; 309 Finding finding = Finding.newBuilder().build(); 310 client.createFinding(parent, findingId, finding); 311 Assert.fail("No exception raised"); 312 } catch (InvalidArgumentException e) { 313 // Expected exception. 314 } 315 } 316 317 @Test createFindingTest3()318 public void createFindingTest3() throws Exception { 319 Finding expectedResponse = 320 Finding.newBuilder() 321 .setName( 322 FindingName.ofOrganizationSourceFindingName( 323 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 324 .toString()) 325 .setParent("parent-995424086") 326 .setResourceName("resourceName-384566343") 327 .setCategory("category50511102") 328 .setExternalUri("externalUri-1153085023") 329 .putAllSourceProperties(new HashMap<String, Value>()) 330 .setSecurityMarks(SecurityMarks.newBuilder().build()) 331 .setEventTime(Timestamp.newBuilder().build()) 332 .setCreateTime(Timestamp.newBuilder().build()) 333 .setCanonicalName("canonicalName2122381727") 334 .build(); 335 mockService.addResponse(expectedResponse); 336 337 String parent = "organizations/organization-8741/sources/source-8741"; 338 Finding finding = Finding.newBuilder().build(); 339 String findingId = "findingId439150212"; 340 341 Finding actualResponse = client.createFinding(parent, finding, findingId); 342 Assert.assertEquals(expectedResponse, actualResponse); 343 344 List<String> actualRequests = mockService.getRequestPaths(); 345 Assert.assertEquals(1, actualRequests.size()); 346 347 String apiClientHeaderKey = 348 mockService 349 .getRequestHeaders() 350 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 351 .iterator() 352 .next(); 353 Assert.assertTrue( 354 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 355 .matcher(apiClientHeaderKey) 356 .matches()); 357 } 358 359 @Test createFindingExceptionTest3()360 public void createFindingExceptionTest3() throws Exception { 361 ApiException exception = 362 ApiExceptionFactory.createException( 363 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 364 mockService.addException(exception); 365 366 try { 367 String parent = "organizations/organization-8741/sources/source-8741"; 368 Finding finding = Finding.newBuilder().build(); 369 String findingId = "findingId439150212"; 370 client.createFinding(parent, finding, findingId); 371 Assert.fail("No exception raised"); 372 } catch (InvalidArgumentException e) { 373 // Expected exception. 374 } 375 } 376 377 @Test createFindingTest4()378 public void createFindingTest4() throws Exception { 379 Finding expectedResponse = 380 Finding.newBuilder() 381 .setName( 382 FindingName.ofOrganizationSourceFindingName( 383 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 384 .toString()) 385 .setParent("parent-995424086") 386 .setResourceName("resourceName-384566343") 387 .setCategory("category50511102") 388 .setExternalUri("externalUri-1153085023") 389 .putAllSourceProperties(new HashMap<String, Value>()) 390 .setSecurityMarks(SecurityMarks.newBuilder().build()) 391 .setEventTime(Timestamp.newBuilder().build()) 392 .setCreateTime(Timestamp.newBuilder().build()) 393 .setCanonicalName("canonicalName2122381727") 394 .build(); 395 mockService.addResponse(expectedResponse); 396 397 String parent = "organizations/organization-8741/sources/source-8741"; 398 String findingId = "findingId439150212"; 399 Finding finding = Finding.newBuilder().build(); 400 401 Finding actualResponse = client.createFinding(parent, findingId, finding); 402 Assert.assertEquals(expectedResponse, actualResponse); 403 404 List<String> actualRequests = mockService.getRequestPaths(); 405 Assert.assertEquals(1, actualRequests.size()); 406 407 String apiClientHeaderKey = 408 mockService 409 .getRequestHeaders() 410 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 411 .iterator() 412 .next(); 413 Assert.assertTrue( 414 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 415 .matcher(apiClientHeaderKey) 416 .matches()); 417 } 418 419 @Test createFindingExceptionTest4()420 public void createFindingExceptionTest4() throws Exception { 421 ApiException exception = 422 ApiExceptionFactory.createException( 423 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 424 mockService.addException(exception); 425 426 try { 427 String parent = "organizations/organization-8741/sources/source-8741"; 428 String findingId = "findingId439150212"; 429 Finding finding = Finding.newBuilder().build(); 430 client.createFinding(parent, findingId, finding); 431 Assert.fail("No exception raised"); 432 } catch (InvalidArgumentException e) { 433 // Expected exception. 434 } 435 } 436 437 @Test createNotificationConfigTest()438 public void createNotificationConfigTest() throws Exception { 439 NotificationConfig expectedResponse = 440 NotificationConfig.newBuilder() 441 .setName( 442 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 443 .setDescription("description-1724546052") 444 .setPubsubTopic("pubsubTopic255880396") 445 .setServiceAccount("serviceAccount1079137720") 446 .build(); 447 mockService.addResponse(expectedResponse); 448 449 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 450 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 451 452 NotificationConfig actualResponse = client.createNotificationConfig(parent, notificationConfig); 453 Assert.assertEquals(expectedResponse, actualResponse); 454 455 List<String> actualRequests = mockService.getRequestPaths(); 456 Assert.assertEquals(1, actualRequests.size()); 457 458 String apiClientHeaderKey = 459 mockService 460 .getRequestHeaders() 461 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 462 .iterator() 463 .next(); 464 Assert.assertTrue( 465 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 466 .matcher(apiClientHeaderKey) 467 .matches()); 468 } 469 470 @Test createNotificationConfigExceptionTest()471 public void createNotificationConfigExceptionTest() throws Exception { 472 ApiException exception = 473 ApiExceptionFactory.createException( 474 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 475 mockService.addException(exception); 476 477 try { 478 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 479 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 480 client.createNotificationConfig(parent, notificationConfig); 481 Assert.fail("No exception raised"); 482 } catch (InvalidArgumentException e) { 483 // Expected exception. 484 } 485 } 486 487 @Test createNotificationConfigTest2()488 public void createNotificationConfigTest2() throws Exception { 489 NotificationConfig expectedResponse = 490 NotificationConfig.newBuilder() 491 .setName( 492 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 493 .setDescription("description-1724546052") 494 .setPubsubTopic("pubsubTopic255880396") 495 .setServiceAccount("serviceAccount1079137720") 496 .build(); 497 mockService.addResponse(expectedResponse); 498 499 String parent = "organizations/organization-8287"; 500 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 501 502 NotificationConfig actualResponse = client.createNotificationConfig(parent, notificationConfig); 503 Assert.assertEquals(expectedResponse, actualResponse); 504 505 List<String> actualRequests = mockService.getRequestPaths(); 506 Assert.assertEquals(1, actualRequests.size()); 507 508 String apiClientHeaderKey = 509 mockService 510 .getRequestHeaders() 511 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 512 .iterator() 513 .next(); 514 Assert.assertTrue( 515 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 516 .matcher(apiClientHeaderKey) 517 .matches()); 518 } 519 520 @Test createNotificationConfigExceptionTest2()521 public void createNotificationConfigExceptionTest2() throws Exception { 522 ApiException exception = 523 ApiExceptionFactory.createException( 524 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 525 mockService.addException(exception); 526 527 try { 528 String parent = "organizations/organization-8287"; 529 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 530 client.createNotificationConfig(parent, notificationConfig); 531 Assert.fail("No exception raised"); 532 } catch (InvalidArgumentException e) { 533 // Expected exception. 534 } 535 } 536 537 @Test createNotificationConfigTest3()538 public void createNotificationConfigTest3() throws Exception { 539 NotificationConfig expectedResponse = 540 NotificationConfig.newBuilder() 541 .setName( 542 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 543 .setDescription("description-1724546052") 544 .setPubsubTopic("pubsubTopic255880396") 545 .setServiceAccount("serviceAccount1079137720") 546 .build(); 547 mockService.addResponse(expectedResponse); 548 549 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 550 String configId = "configId-580140035"; 551 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 552 553 NotificationConfig actualResponse = 554 client.createNotificationConfig(parent, configId, notificationConfig); 555 Assert.assertEquals(expectedResponse, actualResponse); 556 557 List<String> actualRequests = mockService.getRequestPaths(); 558 Assert.assertEquals(1, actualRequests.size()); 559 560 String apiClientHeaderKey = 561 mockService 562 .getRequestHeaders() 563 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 564 .iterator() 565 .next(); 566 Assert.assertTrue( 567 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 568 .matcher(apiClientHeaderKey) 569 .matches()); 570 } 571 572 @Test createNotificationConfigExceptionTest3()573 public void createNotificationConfigExceptionTest3() throws Exception { 574 ApiException exception = 575 ApiExceptionFactory.createException( 576 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 577 mockService.addException(exception); 578 579 try { 580 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 581 String configId = "configId-580140035"; 582 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 583 client.createNotificationConfig(parent, configId, notificationConfig); 584 Assert.fail("No exception raised"); 585 } catch (InvalidArgumentException e) { 586 // Expected exception. 587 } 588 } 589 590 @Test createNotificationConfigTest4()591 public void createNotificationConfigTest4() throws Exception { 592 NotificationConfig expectedResponse = 593 NotificationConfig.newBuilder() 594 .setName( 595 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 596 .setDescription("description-1724546052") 597 .setPubsubTopic("pubsubTopic255880396") 598 .setServiceAccount("serviceAccount1079137720") 599 .build(); 600 mockService.addResponse(expectedResponse); 601 602 String parent = "organizations/organization-8287"; 603 String configId = "configId-580140035"; 604 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 605 606 NotificationConfig actualResponse = 607 client.createNotificationConfig(parent, configId, notificationConfig); 608 Assert.assertEquals(expectedResponse, actualResponse); 609 610 List<String> actualRequests = mockService.getRequestPaths(); 611 Assert.assertEquals(1, actualRequests.size()); 612 613 String apiClientHeaderKey = 614 mockService 615 .getRequestHeaders() 616 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 617 .iterator() 618 .next(); 619 Assert.assertTrue( 620 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 621 .matcher(apiClientHeaderKey) 622 .matches()); 623 } 624 625 @Test createNotificationConfigExceptionTest4()626 public void createNotificationConfigExceptionTest4() throws Exception { 627 ApiException exception = 628 ApiExceptionFactory.createException( 629 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 630 mockService.addException(exception); 631 632 try { 633 String parent = "organizations/organization-8287"; 634 String configId = "configId-580140035"; 635 NotificationConfig notificationConfig = NotificationConfig.newBuilder().build(); 636 client.createNotificationConfig(parent, configId, notificationConfig); 637 Assert.fail("No exception raised"); 638 } catch (InvalidArgumentException e) { 639 // Expected exception. 640 } 641 } 642 643 @Test deleteNotificationConfigTest()644 public void deleteNotificationConfigTest() throws Exception { 645 Empty expectedResponse = Empty.newBuilder().build(); 646 mockService.addResponse(expectedResponse); 647 648 NotificationConfigName name = 649 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]"); 650 651 client.deleteNotificationConfig(name); 652 653 List<String> actualRequests = mockService.getRequestPaths(); 654 Assert.assertEquals(1, actualRequests.size()); 655 656 String apiClientHeaderKey = 657 mockService 658 .getRequestHeaders() 659 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 660 .iterator() 661 .next(); 662 Assert.assertTrue( 663 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 664 .matcher(apiClientHeaderKey) 665 .matches()); 666 } 667 668 @Test deleteNotificationConfigExceptionTest()669 public void deleteNotificationConfigExceptionTest() throws Exception { 670 ApiException exception = 671 ApiExceptionFactory.createException( 672 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 673 mockService.addException(exception); 674 675 try { 676 NotificationConfigName name = 677 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]"); 678 client.deleteNotificationConfig(name); 679 Assert.fail("No exception raised"); 680 } catch (InvalidArgumentException e) { 681 // Expected exception. 682 } 683 } 684 685 @Test deleteNotificationConfigTest2()686 public void deleteNotificationConfigTest2() throws Exception { 687 Empty expectedResponse = Empty.newBuilder().build(); 688 mockService.addResponse(expectedResponse); 689 690 String name = "organizations/organization-7374/notificationConfigs/notificationConfig-7374"; 691 692 client.deleteNotificationConfig(name); 693 694 List<String> actualRequests = mockService.getRequestPaths(); 695 Assert.assertEquals(1, actualRequests.size()); 696 697 String apiClientHeaderKey = 698 mockService 699 .getRequestHeaders() 700 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 701 .iterator() 702 .next(); 703 Assert.assertTrue( 704 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 705 .matcher(apiClientHeaderKey) 706 .matches()); 707 } 708 709 @Test deleteNotificationConfigExceptionTest2()710 public void deleteNotificationConfigExceptionTest2() throws Exception { 711 ApiException exception = 712 ApiExceptionFactory.createException( 713 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 714 mockService.addException(exception); 715 716 try { 717 String name = "organizations/organization-7374/notificationConfigs/notificationConfig-7374"; 718 client.deleteNotificationConfig(name); 719 Assert.fail("No exception raised"); 720 } catch (InvalidArgumentException e) { 721 // Expected exception. 722 } 723 } 724 725 @Test getIamPolicyTest()726 public void getIamPolicyTest() throws Exception { 727 Policy expectedResponse = 728 Policy.newBuilder() 729 .setVersion(351608024) 730 .addAllBindings(new ArrayList<Binding>()) 731 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 732 .setEtag(ByteString.EMPTY) 733 .build(); 734 mockService.addResponse(expectedResponse); 735 736 ResourceName resource = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 737 738 Policy actualResponse = client.getIamPolicy(resource); 739 Assert.assertEquals(expectedResponse, actualResponse); 740 741 List<String> actualRequests = mockService.getRequestPaths(); 742 Assert.assertEquals(1, actualRequests.size()); 743 744 String apiClientHeaderKey = 745 mockService 746 .getRequestHeaders() 747 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 748 .iterator() 749 .next(); 750 Assert.assertTrue( 751 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 752 .matcher(apiClientHeaderKey) 753 .matches()); 754 } 755 756 @Test getIamPolicyExceptionTest()757 public void getIamPolicyExceptionTest() throws Exception { 758 ApiException exception = 759 ApiExceptionFactory.createException( 760 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 761 mockService.addException(exception); 762 763 try { 764 ResourceName resource = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 765 client.getIamPolicy(resource); 766 Assert.fail("No exception raised"); 767 } catch (InvalidArgumentException e) { 768 // Expected exception. 769 } 770 } 771 772 @Test getIamPolicyTest2()773 public void getIamPolicyTest2() throws Exception { 774 Policy expectedResponse = 775 Policy.newBuilder() 776 .setVersion(351608024) 777 .addAllBindings(new ArrayList<Binding>()) 778 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 779 .setEtag(ByteString.EMPTY) 780 .build(); 781 mockService.addResponse(expectedResponse); 782 783 String resource = "organizations/organization-3393/sources/source-3393"; 784 785 Policy actualResponse = client.getIamPolicy(resource); 786 Assert.assertEquals(expectedResponse, actualResponse); 787 788 List<String> actualRequests = mockService.getRequestPaths(); 789 Assert.assertEquals(1, actualRequests.size()); 790 791 String apiClientHeaderKey = 792 mockService 793 .getRequestHeaders() 794 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 795 .iterator() 796 .next(); 797 Assert.assertTrue( 798 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 799 .matcher(apiClientHeaderKey) 800 .matches()); 801 } 802 803 @Test getIamPolicyExceptionTest2()804 public void getIamPolicyExceptionTest2() throws Exception { 805 ApiException exception = 806 ApiExceptionFactory.createException( 807 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 808 mockService.addException(exception); 809 810 try { 811 String resource = "organizations/organization-3393/sources/source-3393"; 812 client.getIamPolicy(resource); 813 Assert.fail("No exception raised"); 814 } catch (InvalidArgumentException e) { 815 // Expected exception. 816 } 817 } 818 819 @Test getNotificationConfigTest()820 public void getNotificationConfigTest() throws Exception { 821 NotificationConfig expectedResponse = 822 NotificationConfig.newBuilder() 823 .setName( 824 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 825 .setDescription("description-1724546052") 826 .setPubsubTopic("pubsubTopic255880396") 827 .setServiceAccount("serviceAccount1079137720") 828 .build(); 829 mockService.addResponse(expectedResponse); 830 831 NotificationConfigName name = 832 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]"); 833 834 NotificationConfig actualResponse = client.getNotificationConfig(name); 835 Assert.assertEquals(expectedResponse, actualResponse); 836 837 List<String> actualRequests = mockService.getRequestPaths(); 838 Assert.assertEquals(1, actualRequests.size()); 839 840 String apiClientHeaderKey = 841 mockService 842 .getRequestHeaders() 843 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 844 .iterator() 845 .next(); 846 Assert.assertTrue( 847 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 848 .matcher(apiClientHeaderKey) 849 .matches()); 850 } 851 852 @Test getNotificationConfigExceptionTest()853 public void getNotificationConfigExceptionTest() throws Exception { 854 ApiException exception = 855 ApiExceptionFactory.createException( 856 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 857 mockService.addException(exception); 858 859 try { 860 NotificationConfigName name = 861 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]"); 862 client.getNotificationConfig(name); 863 Assert.fail("No exception raised"); 864 } catch (InvalidArgumentException e) { 865 // Expected exception. 866 } 867 } 868 869 @Test getNotificationConfigTest2()870 public void getNotificationConfigTest2() throws Exception { 871 NotificationConfig expectedResponse = 872 NotificationConfig.newBuilder() 873 .setName( 874 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 875 .setDescription("description-1724546052") 876 .setPubsubTopic("pubsubTopic255880396") 877 .setServiceAccount("serviceAccount1079137720") 878 .build(); 879 mockService.addResponse(expectedResponse); 880 881 String name = "organizations/organization-7374/notificationConfigs/notificationConfig-7374"; 882 883 NotificationConfig actualResponse = client.getNotificationConfig(name); 884 Assert.assertEquals(expectedResponse, actualResponse); 885 886 List<String> actualRequests = mockService.getRequestPaths(); 887 Assert.assertEquals(1, actualRequests.size()); 888 889 String apiClientHeaderKey = 890 mockService 891 .getRequestHeaders() 892 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 893 .iterator() 894 .next(); 895 Assert.assertTrue( 896 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 897 .matcher(apiClientHeaderKey) 898 .matches()); 899 } 900 901 @Test getNotificationConfigExceptionTest2()902 public void getNotificationConfigExceptionTest2() throws Exception { 903 ApiException exception = 904 ApiExceptionFactory.createException( 905 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 906 mockService.addException(exception); 907 908 try { 909 String name = "organizations/organization-7374/notificationConfigs/notificationConfig-7374"; 910 client.getNotificationConfig(name); 911 Assert.fail("No exception raised"); 912 } catch (InvalidArgumentException e) { 913 // Expected exception. 914 } 915 } 916 917 @Test getOrganizationSettingsTest()918 public void getOrganizationSettingsTest() throws Exception { 919 OrganizationSettings expectedResponse = 920 OrganizationSettings.newBuilder() 921 .setName(OrganizationSettingsName.of("[ORGANIZATION]").toString()) 922 .setEnableAssetDiscovery(true) 923 .setAssetDiscoveryConfig(OrganizationSettings.AssetDiscoveryConfig.newBuilder().build()) 924 .build(); 925 mockService.addResponse(expectedResponse); 926 927 OrganizationSettingsName name = OrganizationSettingsName.of("[ORGANIZATION]"); 928 929 OrganizationSettings actualResponse = client.getOrganizationSettings(name); 930 Assert.assertEquals(expectedResponse, actualResponse); 931 932 List<String> actualRequests = mockService.getRequestPaths(); 933 Assert.assertEquals(1, actualRequests.size()); 934 935 String apiClientHeaderKey = 936 mockService 937 .getRequestHeaders() 938 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 939 .iterator() 940 .next(); 941 Assert.assertTrue( 942 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 943 .matcher(apiClientHeaderKey) 944 .matches()); 945 } 946 947 @Test getOrganizationSettingsExceptionTest()948 public void getOrganizationSettingsExceptionTest() throws Exception { 949 ApiException exception = 950 ApiExceptionFactory.createException( 951 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 952 mockService.addException(exception); 953 954 try { 955 OrganizationSettingsName name = OrganizationSettingsName.of("[ORGANIZATION]"); 956 client.getOrganizationSettings(name); 957 Assert.fail("No exception raised"); 958 } catch (InvalidArgumentException e) { 959 // Expected exception. 960 } 961 } 962 963 @Test getOrganizationSettingsTest2()964 public void getOrganizationSettingsTest2() throws Exception { 965 OrganizationSettings expectedResponse = 966 OrganizationSettings.newBuilder() 967 .setName(OrganizationSettingsName.of("[ORGANIZATION]").toString()) 968 .setEnableAssetDiscovery(true) 969 .setAssetDiscoveryConfig(OrganizationSettings.AssetDiscoveryConfig.newBuilder().build()) 970 .build(); 971 mockService.addResponse(expectedResponse); 972 973 String name = "organizations/organization-9995/organizationSettings"; 974 975 OrganizationSettings actualResponse = client.getOrganizationSettings(name); 976 Assert.assertEquals(expectedResponse, actualResponse); 977 978 List<String> actualRequests = mockService.getRequestPaths(); 979 Assert.assertEquals(1, actualRequests.size()); 980 981 String apiClientHeaderKey = 982 mockService 983 .getRequestHeaders() 984 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 985 .iterator() 986 .next(); 987 Assert.assertTrue( 988 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 989 .matcher(apiClientHeaderKey) 990 .matches()); 991 } 992 993 @Test getOrganizationSettingsExceptionTest2()994 public void getOrganizationSettingsExceptionTest2() throws Exception { 995 ApiException exception = 996 ApiExceptionFactory.createException( 997 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 998 mockService.addException(exception); 999 1000 try { 1001 String name = "organizations/organization-9995/organizationSettings"; 1002 client.getOrganizationSettings(name); 1003 Assert.fail("No exception raised"); 1004 } catch (InvalidArgumentException e) { 1005 // Expected exception. 1006 } 1007 } 1008 1009 @Test getSourceTest()1010 public void getSourceTest() throws Exception { 1011 Source expectedResponse = 1012 Source.newBuilder() 1013 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 1014 .setDisplayName("displayName1714148973") 1015 .setDescription("description-1724546052") 1016 .setCanonicalName("canonicalName2122381727") 1017 .build(); 1018 mockService.addResponse(expectedResponse); 1019 1020 SourceName name = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 1021 1022 Source actualResponse = client.getSource(name); 1023 Assert.assertEquals(expectedResponse, actualResponse); 1024 1025 List<String> actualRequests = mockService.getRequestPaths(); 1026 Assert.assertEquals(1, actualRequests.size()); 1027 1028 String apiClientHeaderKey = 1029 mockService 1030 .getRequestHeaders() 1031 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1032 .iterator() 1033 .next(); 1034 Assert.assertTrue( 1035 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1036 .matcher(apiClientHeaderKey) 1037 .matches()); 1038 } 1039 1040 @Test getSourceExceptionTest()1041 public void getSourceExceptionTest() throws Exception { 1042 ApiException exception = 1043 ApiExceptionFactory.createException( 1044 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1045 mockService.addException(exception); 1046 1047 try { 1048 SourceName name = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 1049 client.getSource(name); 1050 Assert.fail("No exception raised"); 1051 } catch (InvalidArgumentException e) { 1052 // Expected exception. 1053 } 1054 } 1055 1056 @Test getSourceTest2()1057 public void getSourceTest2() throws Exception { 1058 Source expectedResponse = 1059 Source.newBuilder() 1060 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 1061 .setDisplayName("displayName1714148973") 1062 .setDescription("description-1724546052") 1063 .setCanonicalName("canonicalName2122381727") 1064 .build(); 1065 mockService.addResponse(expectedResponse); 1066 1067 String name = "organizations/organization-7292/sources/source-7292"; 1068 1069 Source actualResponse = client.getSource(name); 1070 Assert.assertEquals(expectedResponse, actualResponse); 1071 1072 List<String> actualRequests = mockService.getRequestPaths(); 1073 Assert.assertEquals(1, actualRequests.size()); 1074 1075 String apiClientHeaderKey = 1076 mockService 1077 .getRequestHeaders() 1078 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1079 .iterator() 1080 .next(); 1081 Assert.assertTrue( 1082 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1083 .matcher(apiClientHeaderKey) 1084 .matches()); 1085 } 1086 1087 @Test getSourceExceptionTest2()1088 public void getSourceExceptionTest2() throws Exception { 1089 ApiException exception = 1090 ApiExceptionFactory.createException( 1091 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1092 mockService.addException(exception); 1093 1094 try { 1095 String name = "organizations/organization-7292/sources/source-7292"; 1096 client.getSource(name); 1097 Assert.fail("No exception raised"); 1098 } catch (InvalidArgumentException e) { 1099 // Expected exception. 1100 } 1101 } 1102 1103 @Test groupAssetsTest()1104 public void groupAssetsTest() throws Exception { 1105 GroupResult responsesElement = GroupResult.newBuilder().build(); 1106 GroupAssetsResponse expectedResponse = 1107 GroupAssetsResponse.newBuilder() 1108 .setNextPageToken("") 1109 .addAllGroupByResults(Arrays.asList(responsesElement)) 1110 .build(); 1111 mockService.addResponse(expectedResponse); 1112 1113 GroupAssetsRequest request = 1114 GroupAssetsRequest.newBuilder() 1115 .setParent(OrganizationName.of("[ORGANIZATION]").toString()) 1116 .setFilter("filter-1274492040") 1117 .setGroupBy("groupBy293428022") 1118 .setCompareDuration(Duration.newBuilder().build()) 1119 .setReadTime(Timestamp.newBuilder().build()) 1120 .setPageToken("pageToken873572522") 1121 .setPageSize(883849137) 1122 .build(); 1123 1124 GroupAssetsPagedResponse pagedListResponse = client.groupAssets(request); 1125 1126 List<GroupResult> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1127 1128 Assert.assertEquals(1, resources.size()); 1129 Assert.assertEquals(expectedResponse.getGroupByResultsList().get(0), resources.get(0)); 1130 1131 List<String> actualRequests = mockService.getRequestPaths(); 1132 Assert.assertEquals(1, actualRequests.size()); 1133 1134 String apiClientHeaderKey = 1135 mockService 1136 .getRequestHeaders() 1137 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1138 .iterator() 1139 .next(); 1140 Assert.assertTrue( 1141 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1142 .matcher(apiClientHeaderKey) 1143 .matches()); 1144 } 1145 1146 @Test groupAssetsExceptionTest()1147 public void groupAssetsExceptionTest() throws Exception { 1148 ApiException exception = 1149 ApiExceptionFactory.createException( 1150 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1151 mockService.addException(exception); 1152 1153 try { 1154 GroupAssetsRequest request = 1155 GroupAssetsRequest.newBuilder() 1156 .setParent(OrganizationName.of("[ORGANIZATION]").toString()) 1157 .setFilter("filter-1274492040") 1158 .setGroupBy("groupBy293428022") 1159 .setCompareDuration(Duration.newBuilder().build()) 1160 .setReadTime(Timestamp.newBuilder().build()) 1161 .setPageToken("pageToken873572522") 1162 .setPageSize(883849137) 1163 .build(); 1164 client.groupAssets(request); 1165 Assert.fail("No exception raised"); 1166 } catch (InvalidArgumentException e) { 1167 // Expected exception. 1168 } 1169 } 1170 1171 @Test groupFindingsTest()1172 public void groupFindingsTest() throws Exception { 1173 GroupResult responsesElement = GroupResult.newBuilder().build(); 1174 GroupFindingsResponse expectedResponse = 1175 GroupFindingsResponse.newBuilder() 1176 .setNextPageToken("") 1177 .addAllGroupByResults(Arrays.asList(responsesElement)) 1178 .build(); 1179 mockService.addResponse(expectedResponse); 1180 1181 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 1182 String groupBy = "groupBy293428022"; 1183 1184 GroupFindingsPagedResponse pagedListResponse = client.groupFindings(parent, groupBy); 1185 1186 List<GroupResult> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1187 1188 Assert.assertEquals(1, resources.size()); 1189 Assert.assertEquals(expectedResponse.getGroupByResultsList().get(0), resources.get(0)); 1190 1191 List<String> actualRequests = mockService.getRequestPaths(); 1192 Assert.assertEquals(1, actualRequests.size()); 1193 1194 String apiClientHeaderKey = 1195 mockService 1196 .getRequestHeaders() 1197 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1198 .iterator() 1199 .next(); 1200 Assert.assertTrue( 1201 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1202 .matcher(apiClientHeaderKey) 1203 .matches()); 1204 } 1205 1206 @Test groupFindingsExceptionTest()1207 public void groupFindingsExceptionTest() throws Exception { 1208 ApiException exception = 1209 ApiExceptionFactory.createException( 1210 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1211 mockService.addException(exception); 1212 1213 try { 1214 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 1215 String groupBy = "groupBy293428022"; 1216 client.groupFindings(parent, groupBy); 1217 Assert.fail("No exception raised"); 1218 } catch (InvalidArgumentException e) { 1219 // Expected exception. 1220 } 1221 } 1222 1223 @Test groupFindingsTest2()1224 public void groupFindingsTest2() throws Exception { 1225 GroupResult responsesElement = GroupResult.newBuilder().build(); 1226 GroupFindingsResponse expectedResponse = 1227 GroupFindingsResponse.newBuilder() 1228 .setNextPageToken("") 1229 .addAllGroupByResults(Arrays.asList(responsesElement)) 1230 .build(); 1231 mockService.addResponse(expectedResponse); 1232 1233 String parent = "organizations/organization-8741/sources/source-8741"; 1234 String groupBy = "groupBy293428022"; 1235 1236 GroupFindingsPagedResponse pagedListResponse = client.groupFindings(parent, groupBy); 1237 1238 List<GroupResult> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1239 1240 Assert.assertEquals(1, resources.size()); 1241 Assert.assertEquals(expectedResponse.getGroupByResultsList().get(0), resources.get(0)); 1242 1243 List<String> actualRequests = mockService.getRequestPaths(); 1244 Assert.assertEquals(1, actualRequests.size()); 1245 1246 String apiClientHeaderKey = 1247 mockService 1248 .getRequestHeaders() 1249 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1250 .iterator() 1251 .next(); 1252 Assert.assertTrue( 1253 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1254 .matcher(apiClientHeaderKey) 1255 .matches()); 1256 } 1257 1258 @Test groupFindingsExceptionTest2()1259 public void groupFindingsExceptionTest2() throws Exception { 1260 ApiException exception = 1261 ApiExceptionFactory.createException( 1262 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1263 mockService.addException(exception); 1264 1265 try { 1266 String parent = "organizations/organization-8741/sources/source-8741"; 1267 String groupBy = "groupBy293428022"; 1268 client.groupFindings(parent, groupBy); 1269 Assert.fail("No exception raised"); 1270 } catch (InvalidArgumentException e) { 1271 // Expected exception. 1272 } 1273 } 1274 1275 @Test listAssetsTest()1276 public void listAssetsTest() throws Exception { 1277 ListAssetsResponse.ListAssetsResult responsesElement = 1278 ListAssetsResponse.ListAssetsResult.newBuilder().build(); 1279 ListAssetsResponse expectedResponse = 1280 ListAssetsResponse.newBuilder() 1281 .setNextPageToken("") 1282 .addAllListAssetsResults(Arrays.asList(responsesElement)) 1283 .build(); 1284 mockService.addResponse(expectedResponse); 1285 1286 FolderName parent = FolderName.of("[FOLDER]"); 1287 1288 ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); 1289 1290 List<ListAssetsResponse.ListAssetsResult> resources = 1291 Lists.newArrayList(pagedListResponse.iterateAll()); 1292 1293 Assert.assertEquals(1, resources.size()); 1294 Assert.assertEquals(expectedResponse.getListAssetsResultsList().get(0), resources.get(0)); 1295 1296 List<String> actualRequests = mockService.getRequestPaths(); 1297 Assert.assertEquals(1, actualRequests.size()); 1298 1299 String apiClientHeaderKey = 1300 mockService 1301 .getRequestHeaders() 1302 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1303 .iterator() 1304 .next(); 1305 Assert.assertTrue( 1306 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1307 .matcher(apiClientHeaderKey) 1308 .matches()); 1309 } 1310 1311 @Test listAssetsExceptionTest()1312 public void listAssetsExceptionTest() throws Exception { 1313 ApiException exception = 1314 ApiExceptionFactory.createException( 1315 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1316 mockService.addException(exception); 1317 1318 try { 1319 FolderName parent = FolderName.of("[FOLDER]"); 1320 client.listAssets(parent); 1321 Assert.fail("No exception raised"); 1322 } catch (InvalidArgumentException e) { 1323 // Expected exception. 1324 } 1325 } 1326 1327 @Test listAssetsTest2()1328 public void listAssetsTest2() throws Exception { 1329 ListAssetsResponse.ListAssetsResult responsesElement = 1330 ListAssetsResponse.ListAssetsResult.newBuilder().build(); 1331 ListAssetsResponse expectedResponse = 1332 ListAssetsResponse.newBuilder() 1333 .setNextPageToken("") 1334 .addAllListAssetsResults(Arrays.asList(responsesElement)) 1335 .build(); 1336 mockService.addResponse(expectedResponse); 1337 1338 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1339 1340 ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); 1341 1342 List<ListAssetsResponse.ListAssetsResult> resources = 1343 Lists.newArrayList(pagedListResponse.iterateAll()); 1344 1345 Assert.assertEquals(1, resources.size()); 1346 Assert.assertEquals(expectedResponse.getListAssetsResultsList().get(0), resources.get(0)); 1347 1348 List<String> actualRequests = mockService.getRequestPaths(); 1349 Assert.assertEquals(1, actualRequests.size()); 1350 1351 String apiClientHeaderKey = 1352 mockService 1353 .getRequestHeaders() 1354 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1355 .iterator() 1356 .next(); 1357 Assert.assertTrue( 1358 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1359 .matcher(apiClientHeaderKey) 1360 .matches()); 1361 } 1362 1363 @Test listAssetsExceptionTest2()1364 public void listAssetsExceptionTest2() throws Exception { 1365 ApiException exception = 1366 ApiExceptionFactory.createException( 1367 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1368 mockService.addException(exception); 1369 1370 try { 1371 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1372 client.listAssets(parent); 1373 Assert.fail("No exception raised"); 1374 } catch (InvalidArgumentException e) { 1375 // Expected exception. 1376 } 1377 } 1378 1379 @Test listAssetsTest3()1380 public void listAssetsTest3() throws Exception { 1381 ListAssetsResponse.ListAssetsResult responsesElement = 1382 ListAssetsResponse.ListAssetsResult.newBuilder().build(); 1383 ListAssetsResponse expectedResponse = 1384 ListAssetsResponse.newBuilder() 1385 .setNextPageToken("") 1386 .addAllListAssetsResults(Arrays.asList(responsesElement)) 1387 .build(); 1388 mockService.addResponse(expectedResponse); 1389 1390 ProjectName parent = ProjectName.of("[PROJECT]"); 1391 1392 ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); 1393 1394 List<ListAssetsResponse.ListAssetsResult> resources = 1395 Lists.newArrayList(pagedListResponse.iterateAll()); 1396 1397 Assert.assertEquals(1, resources.size()); 1398 Assert.assertEquals(expectedResponse.getListAssetsResultsList().get(0), resources.get(0)); 1399 1400 List<String> actualRequests = mockService.getRequestPaths(); 1401 Assert.assertEquals(1, actualRequests.size()); 1402 1403 String apiClientHeaderKey = 1404 mockService 1405 .getRequestHeaders() 1406 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1407 .iterator() 1408 .next(); 1409 Assert.assertTrue( 1410 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1411 .matcher(apiClientHeaderKey) 1412 .matches()); 1413 } 1414 1415 @Test listAssetsExceptionTest3()1416 public void listAssetsExceptionTest3() throws Exception { 1417 ApiException exception = 1418 ApiExceptionFactory.createException( 1419 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1420 mockService.addException(exception); 1421 1422 try { 1423 ProjectName parent = ProjectName.of("[PROJECT]"); 1424 client.listAssets(parent); 1425 Assert.fail("No exception raised"); 1426 } catch (InvalidArgumentException e) { 1427 // Expected exception. 1428 } 1429 } 1430 1431 @Test listAssetsTest4()1432 public void listAssetsTest4() throws Exception { 1433 ListAssetsResponse.ListAssetsResult responsesElement = 1434 ListAssetsResponse.ListAssetsResult.newBuilder().build(); 1435 ListAssetsResponse expectedResponse = 1436 ListAssetsResponse.newBuilder() 1437 .setNextPageToken("") 1438 .addAllListAssetsResults(Arrays.asList(responsesElement)) 1439 .build(); 1440 mockService.addResponse(expectedResponse); 1441 1442 String parent = "organizations/organization-8287"; 1443 1444 ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); 1445 1446 List<ListAssetsResponse.ListAssetsResult> resources = 1447 Lists.newArrayList(pagedListResponse.iterateAll()); 1448 1449 Assert.assertEquals(1, resources.size()); 1450 Assert.assertEquals(expectedResponse.getListAssetsResultsList().get(0), resources.get(0)); 1451 1452 List<String> actualRequests = mockService.getRequestPaths(); 1453 Assert.assertEquals(1, actualRequests.size()); 1454 1455 String apiClientHeaderKey = 1456 mockService 1457 .getRequestHeaders() 1458 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1459 .iterator() 1460 .next(); 1461 Assert.assertTrue( 1462 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1463 .matcher(apiClientHeaderKey) 1464 .matches()); 1465 } 1466 1467 @Test listAssetsExceptionTest4()1468 public void listAssetsExceptionTest4() throws Exception { 1469 ApiException exception = 1470 ApiExceptionFactory.createException( 1471 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1472 mockService.addException(exception); 1473 1474 try { 1475 String parent = "organizations/organization-8287"; 1476 client.listAssets(parent); 1477 Assert.fail("No exception raised"); 1478 } catch (InvalidArgumentException e) { 1479 // Expected exception. 1480 } 1481 } 1482 1483 @Test listFindingsTest()1484 public void listFindingsTest() throws Exception { 1485 ListFindingsResponse.ListFindingsResult responsesElement = 1486 ListFindingsResponse.ListFindingsResult.newBuilder().build(); 1487 ListFindingsResponse expectedResponse = 1488 ListFindingsResponse.newBuilder() 1489 .setNextPageToken("") 1490 .addAllListFindingsResults(Arrays.asList(responsesElement)) 1491 .build(); 1492 mockService.addResponse(expectedResponse); 1493 1494 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 1495 1496 ListFindingsPagedResponse pagedListResponse = client.listFindings(parent); 1497 1498 List<ListFindingsResponse.ListFindingsResult> resources = 1499 Lists.newArrayList(pagedListResponse.iterateAll()); 1500 1501 Assert.assertEquals(1, resources.size()); 1502 Assert.assertEquals(expectedResponse.getListFindingsResultsList().get(0), resources.get(0)); 1503 1504 List<String> actualRequests = mockService.getRequestPaths(); 1505 Assert.assertEquals(1, actualRequests.size()); 1506 1507 String apiClientHeaderKey = 1508 mockService 1509 .getRequestHeaders() 1510 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1511 .iterator() 1512 .next(); 1513 Assert.assertTrue( 1514 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1515 .matcher(apiClientHeaderKey) 1516 .matches()); 1517 } 1518 1519 @Test listFindingsExceptionTest()1520 public void listFindingsExceptionTest() throws Exception { 1521 ApiException exception = 1522 ApiExceptionFactory.createException( 1523 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1524 mockService.addException(exception); 1525 1526 try { 1527 SourceName parent = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 1528 client.listFindings(parent); 1529 Assert.fail("No exception raised"); 1530 } catch (InvalidArgumentException e) { 1531 // Expected exception. 1532 } 1533 } 1534 1535 @Test listFindingsTest2()1536 public void listFindingsTest2() throws Exception { 1537 ListFindingsResponse.ListFindingsResult responsesElement = 1538 ListFindingsResponse.ListFindingsResult.newBuilder().build(); 1539 ListFindingsResponse expectedResponse = 1540 ListFindingsResponse.newBuilder() 1541 .setNextPageToken("") 1542 .addAllListFindingsResults(Arrays.asList(responsesElement)) 1543 .build(); 1544 mockService.addResponse(expectedResponse); 1545 1546 String parent = "organizations/organization-8741/sources/source-8741"; 1547 1548 ListFindingsPagedResponse pagedListResponse = client.listFindings(parent); 1549 1550 List<ListFindingsResponse.ListFindingsResult> resources = 1551 Lists.newArrayList(pagedListResponse.iterateAll()); 1552 1553 Assert.assertEquals(1, resources.size()); 1554 Assert.assertEquals(expectedResponse.getListFindingsResultsList().get(0), resources.get(0)); 1555 1556 List<String> actualRequests = mockService.getRequestPaths(); 1557 Assert.assertEquals(1, actualRequests.size()); 1558 1559 String apiClientHeaderKey = 1560 mockService 1561 .getRequestHeaders() 1562 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1563 .iterator() 1564 .next(); 1565 Assert.assertTrue( 1566 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1567 .matcher(apiClientHeaderKey) 1568 .matches()); 1569 } 1570 1571 @Test listFindingsExceptionTest2()1572 public void listFindingsExceptionTest2() throws Exception { 1573 ApiException exception = 1574 ApiExceptionFactory.createException( 1575 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1576 mockService.addException(exception); 1577 1578 try { 1579 String parent = "organizations/organization-8741/sources/source-8741"; 1580 client.listFindings(parent); 1581 Assert.fail("No exception raised"); 1582 } catch (InvalidArgumentException e) { 1583 // Expected exception. 1584 } 1585 } 1586 1587 @Test listNotificationConfigsTest()1588 public void listNotificationConfigsTest() throws Exception { 1589 NotificationConfig responsesElement = NotificationConfig.newBuilder().build(); 1590 ListNotificationConfigsResponse expectedResponse = 1591 ListNotificationConfigsResponse.newBuilder() 1592 .setNextPageToken("") 1593 .addAllNotificationConfigs(Arrays.asList(responsesElement)) 1594 .build(); 1595 mockService.addResponse(expectedResponse); 1596 1597 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1598 1599 ListNotificationConfigsPagedResponse pagedListResponse = client.listNotificationConfigs(parent); 1600 1601 List<NotificationConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1602 1603 Assert.assertEquals(1, resources.size()); 1604 Assert.assertEquals(expectedResponse.getNotificationConfigsList().get(0), resources.get(0)); 1605 1606 List<String> actualRequests = mockService.getRequestPaths(); 1607 Assert.assertEquals(1, actualRequests.size()); 1608 1609 String apiClientHeaderKey = 1610 mockService 1611 .getRequestHeaders() 1612 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1613 .iterator() 1614 .next(); 1615 Assert.assertTrue( 1616 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1617 .matcher(apiClientHeaderKey) 1618 .matches()); 1619 } 1620 1621 @Test listNotificationConfigsExceptionTest()1622 public void listNotificationConfigsExceptionTest() throws Exception { 1623 ApiException exception = 1624 ApiExceptionFactory.createException( 1625 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1626 mockService.addException(exception); 1627 1628 try { 1629 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1630 client.listNotificationConfigs(parent); 1631 Assert.fail("No exception raised"); 1632 } catch (InvalidArgumentException e) { 1633 // Expected exception. 1634 } 1635 } 1636 1637 @Test listNotificationConfigsTest2()1638 public void listNotificationConfigsTest2() throws Exception { 1639 NotificationConfig responsesElement = NotificationConfig.newBuilder().build(); 1640 ListNotificationConfigsResponse expectedResponse = 1641 ListNotificationConfigsResponse.newBuilder() 1642 .setNextPageToken("") 1643 .addAllNotificationConfigs(Arrays.asList(responsesElement)) 1644 .build(); 1645 mockService.addResponse(expectedResponse); 1646 1647 String parent = "organizations/organization-8287"; 1648 1649 ListNotificationConfigsPagedResponse pagedListResponse = client.listNotificationConfigs(parent); 1650 1651 List<NotificationConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1652 1653 Assert.assertEquals(1, resources.size()); 1654 Assert.assertEquals(expectedResponse.getNotificationConfigsList().get(0), resources.get(0)); 1655 1656 List<String> actualRequests = mockService.getRequestPaths(); 1657 Assert.assertEquals(1, actualRequests.size()); 1658 1659 String apiClientHeaderKey = 1660 mockService 1661 .getRequestHeaders() 1662 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1663 .iterator() 1664 .next(); 1665 Assert.assertTrue( 1666 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1667 .matcher(apiClientHeaderKey) 1668 .matches()); 1669 } 1670 1671 @Test listNotificationConfigsExceptionTest2()1672 public void listNotificationConfigsExceptionTest2() throws Exception { 1673 ApiException exception = 1674 ApiExceptionFactory.createException( 1675 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1676 mockService.addException(exception); 1677 1678 try { 1679 String parent = "organizations/organization-8287"; 1680 client.listNotificationConfigs(parent); 1681 Assert.fail("No exception raised"); 1682 } catch (InvalidArgumentException e) { 1683 // Expected exception. 1684 } 1685 } 1686 1687 @Test listSourcesTest()1688 public void listSourcesTest() throws Exception { 1689 Source responsesElement = Source.newBuilder().build(); 1690 ListSourcesResponse expectedResponse = 1691 ListSourcesResponse.newBuilder() 1692 .setNextPageToken("") 1693 .addAllSources(Arrays.asList(responsesElement)) 1694 .build(); 1695 mockService.addResponse(expectedResponse); 1696 1697 FolderName parent = FolderName.of("[FOLDER]"); 1698 1699 ListSourcesPagedResponse pagedListResponse = client.listSources(parent); 1700 1701 List<Source> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1702 1703 Assert.assertEquals(1, resources.size()); 1704 Assert.assertEquals(expectedResponse.getSourcesList().get(0), resources.get(0)); 1705 1706 List<String> actualRequests = mockService.getRequestPaths(); 1707 Assert.assertEquals(1, actualRequests.size()); 1708 1709 String apiClientHeaderKey = 1710 mockService 1711 .getRequestHeaders() 1712 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1713 .iterator() 1714 .next(); 1715 Assert.assertTrue( 1716 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1717 .matcher(apiClientHeaderKey) 1718 .matches()); 1719 } 1720 1721 @Test listSourcesExceptionTest()1722 public void listSourcesExceptionTest() throws Exception { 1723 ApiException exception = 1724 ApiExceptionFactory.createException( 1725 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1726 mockService.addException(exception); 1727 1728 try { 1729 FolderName parent = FolderName.of("[FOLDER]"); 1730 client.listSources(parent); 1731 Assert.fail("No exception raised"); 1732 } catch (InvalidArgumentException e) { 1733 // Expected exception. 1734 } 1735 } 1736 1737 @Test listSourcesTest2()1738 public void listSourcesTest2() throws Exception { 1739 Source responsesElement = Source.newBuilder().build(); 1740 ListSourcesResponse expectedResponse = 1741 ListSourcesResponse.newBuilder() 1742 .setNextPageToken("") 1743 .addAllSources(Arrays.asList(responsesElement)) 1744 .build(); 1745 mockService.addResponse(expectedResponse); 1746 1747 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1748 1749 ListSourcesPagedResponse pagedListResponse = client.listSources(parent); 1750 1751 List<Source> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1752 1753 Assert.assertEquals(1, resources.size()); 1754 Assert.assertEquals(expectedResponse.getSourcesList().get(0), resources.get(0)); 1755 1756 List<String> actualRequests = mockService.getRequestPaths(); 1757 Assert.assertEquals(1, actualRequests.size()); 1758 1759 String apiClientHeaderKey = 1760 mockService 1761 .getRequestHeaders() 1762 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1763 .iterator() 1764 .next(); 1765 Assert.assertTrue( 1766 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1767 .matcher(apiClientHeaderKey) 1768 .matches()); 1769 } 1770 1771 @Test listSourcesExceptionTest2()1772 public void listSourcesExceptionTest2() throws Exception { 1773 ApiException exception = 1774 ApiExceptionFactory.createException( 1775 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1776 mockService.addException(exception); 1777 1778 try { 1779 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1780 client.listSources(parent); 1781 Assert.fail("No exception raised"); 1782 } catch (InvalidArgumentException e) { 1783 // Expected exception. 1784 } 1785 } 1786 1787 @Test listSourcesTest3()1788 public void listSourcesTest3() throws Exception { 1789 Source responsesElement = Source.newBuilder().build(); 1790 ListSourcesResponse expectedResponse = 1791 ListSourcesResponse.newBuilder() 1792 .setNextPageToken("") 1793 .addAllSources(Arrays.asList(responsesElement)) 1794 .build(); 1795 mockService.addResponse(expectedResponse); 1796 1797 ProjectName parent = ProjectName.of("[PROJECT]"); 1798 1799 ListSourcesPagedResponse pagedListResponse = client.listSources(parent); 1800 1801 List<Source> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1802 1803 Assert.assertEquals(1, resources.size()); 1804 Assert.assertEquals(expectedResponse.getSourcesList().get(0), resources.get(0)); 1805 1806 List<String> actualRequests = mockService.getRequestPaths(); 1807 Assert.assertEquals(1, actualRequests.size()); 1808 1809 String apiClientHeaderKey = 1810 mockService 1811 .getRequestHeaders() 1812 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1813 .iterator() 1814 .next(); 1815 Assert.assertTrue( 1816 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1817 .matcher(apiClientHeaderKey) 1818 .matches()); 1819 } 1820 1821 @Test listSourcesExceptionTest3()1822 public void listSourcesExceptionTest3() throws Exception { 1823 ApiException exception = 1824 ApiExceptionFactory.createException( 1825 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1826 mockService.addException(exception); 1827 1828 try { 1829 ProjectName parent = ProjectName.of("[PROJECT]"); 1830 client.listSources(parent); 1831 Assert.fail("No exception raised"); 1832 } catch (InvalidArgumentException e) { 1833 // Expected exception. 1834 } 1835 } 1836 1837 @Test listSourcesTest4()1838 public void listSourcesTest4() throws Exception { 1839 Source responsesElement = Source.newBuilder().build(); 1840 ListSourcesResponse expectedResponse = 1841 ListSourcesResponse.newBuilder() 1842 .setNextPageToken("") 1843 .addAllSources(Arrays.asList(responsesElement)) 1844 .build(); 1845 mockService.addResponse(expectedResponse); 1846 1847 String parent = "organizations/organization-8287"; 1848 1849 ListSourcesPagedResponse pagedListResponse = client.listSources(parent); 1850 1851 List<Source> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1852 1853 Assert.assertEquals(1, resources.size()); 1854 Assert.assertEquals(expectedResponse.getSourcesList().get(0), resources.get(0)); 1855 1856 List<String> actualRequests = mockService.getRequestPaths(); 1857 Assert.assertEquals(1, actualRequests.size()); 1858 1859 String apiClientHeaderKey = 1860 mockService 1861 .getRequestHeaders() 1862 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1863 .iterator() 1864 .next(); 1865 Assert.assertTrue( 1866 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1867 .matcher(apiClientHeaderKey) 1868 .matches()); 1869 } 1870 1871 @Test listSourcesExceptionTest4()1872 public void listSourcesExceptionTest4() throws Exception { 1873 ApiException exception = 1874 ApiExceptionFactory.createException( 1875 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1876 mockService.addException(exception); 1877 1878 try { 1879 String parent = "organizations/organization-8287"; 1880 client.listSources(parent); 1881 Assert.fail("No exception raised"); 1882 } catch (InvalidArgumentException e) { 1883 // Expected exception. 1884 } 1885 } 1886 1887 @Test runAssetDiscoveryTest()1888 public void runAssetDiscoveryTest() throws Exception { 1889 RunAssetDiscoveryResponse expectedResponse = 1890 RunAssetDiscoveryResponse.newBuilder().setDuration(Duration.newBuilder().build()).build(); 1891 Operation resultOperation = 1892 Operation.newBuilder() 1893 .setName("runAssetDiscoveryTest") 1894 .setDone(true) 1895 .setResponse(Any.pack(expectedResponse)) 1896 .build(); 1897 mockService.addResponse(resultOperation); 1898 1899 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1900 1901 RunAssetDiscoveryResponse actualResponse = client.runAssetDiscoveryAsync(parent).get(); 1902 Assert.assertEquals(expectedResponse, actualResponse); 1903 1904 List<String> actualRequests = mockService.getRequestPaths(); 1905 Assert.assertEquals(1, actualRequests.size()); 1906 1907 String apiClientHeaderKey = 1908 mockService 1909 .getRequestHeaders() 1910 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1911 .iterator() 1912 .next(); 1913 Assert.assertTrue( 1914 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1915 .matcher(apiClientHeaderKey) 1916 .matches()); 1917 } 1918 1919 @Test runAssetDiscoveryExceptionTest()1920 public void runAssetDiscoveryExceptionTest() throws Exception { 1921 ApiException exception = 1922 ApiExceptionFactory.createException( 1923 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1924 mockService.addException(exception); 1925 1926 try { 1927 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1928 client.runAssetDiscoveryAsync(parent).get(); 1929 Assert.fail("No exception raised"); 1930 } catch (ExecutionException e) { 1931 } 1932 } 1933 1934 @Test runAssetDiscoveryTest2()1935 public void runAssetDiscoveryTest2() throws Exception { 1936 RunAssetDiscoveryResponse expectedResponse = 1937 RunAssetDiscoveryResponse.newBuilder().setDuration(Duration.newBuilder().build()).build(); 1938 Operation resultOperation = 1939 Operation.newBuilder() 1940 .setName("runAssetDiscoveryTest") 1941 .setDone(true) 1942 .setResponse(Any.pack(expectedResponse)) 1943 .build(); 1944 mockService.addResponse(resultOperation); 1945 1946 String parent = "organizations/organization-8287"; 1947 1948 RunAssetDiscoveryResponse actualResponse = client.runAssetDiscoveryAsync(parent).get(); 1949 Assert.assertEquals(expectedResponse, actualResponse); 1950 1951 List<String> actualRequests = mockService.getRequestPaths(); 1952 Assert.assertEquals(1, actualRequests.size()); 1953 1954 String apiClientHeaderKey = 1955 mockService 1956 .getRequestHeaders() 1957 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1958 .iterator() 1959 .next(); 1960 Assert.assertTrue( 1961 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1962 .matcher(apiClientHeaderKey) 1963 .matches()); 1964 } 1965 1966 @Test runAssetDiscoveryExceptionTest2()1967 public void runAssetDiscoveryExceptionTest2() throws Exception { 1968 ApiException exception = 1969 ApiExceptionFactory.createException( 1970 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1971 mockService.addException(exception); 1972 1973 try { 1974 String parent = "organizations/organization-8287"; 1975 client.runAssetDiscoveryAsync(parent).get(); 1976 Assert.fail("No exception raised"); 1977 } catch (ExecutionException e) { 1978 } 1979 } 1980 1981 @Test setFindingStateTest()1982 public void setFindingStateTest() throws Exception { 1983 Finding expectedResponse = 1984 Finding.newBuilder() 1985 .setName( 1986 FindingName.ofOrganizationSourceFindingName( 1987 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 1988 .toString()) 1989 .setParent("parent-995424086") 1990 .setResourceName("resourceName-384566343") 1991 .setCategory("category50511102") 1992 .setExternalUri("externalUri-1153085023") 1993 .putAllSourceProperties(new HashMap<String, Value>()) 1994 .setSecurityMarks(SecurityMarks.newBuilder().build()) 1995 .setEventTime(Timestamp.newBuilder().build()) 1996 .setCreateTime(Timestamp.newBuilder().build()) 1997 .setCanonicalName("canonicalName2122381727") 1998 .build(); 1999 mockService.addResponse(expectedResponse); 2000 2001 FindingName name = 2002 FindingName.ofOrganizationSourceFindingName("[ORGANIZATION]", "[SOURCE]", "[FINDING]"); 2003 Finding.State state = Finding.State.forNumber(0); 2004 Timestamp startTime = Timestamp.newBuilder().build(); 2005 2006 Finding actualResponse = client.setFindingState(name, state, startTime); 2007 Assert.assertEquals(expectedResponse, actualResponse); 2008 2009 List<String> actualRequests = mockService.getRequestPaths(); 2010 Assert.assertEquals(1, actualRequests.size()); 2011 2012 String apiClientHeaderKey = 2013 mockService 2014 .getRequestHeaders() 2015 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2016 .iterator() 2017 .next(); 2018 Assert.assertTrue( 2019 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2020 .matcher(apiClientHeaderKey) 2021 .matches()); 2022 } 2023 2024 @Test setFindingStateExceptionTest()2025 public void setFindingStateExceptionTest() throws Exception { 2026 ApiException exception = 2027 ApiExceptionFactory.createException( 2028 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2029 mockService.addException(exception); 2030 2031 try { 2032 FindingName name = 2033 FindingName.ofOrganizationSourceFindingName("[ORGANIZATION]", "[SOURCE]", "[FINDING]"); 2034 Finding.State state = Finding.State.forNumber(0); 2035 Timestamp startTime = Timestamp.newBuilder().build(); 2036 client.setFindingState(name, state, startTime); 2037 Assert.fail("No exception raised"); 2038 } catch (InvalidArgumentException e) { 2039 // Expected exception. 2040 } 2041 } 2042 2043 @Test setFindingStateTest2()2044 public void setFindingStateTest2() throws Exception { 2045 Finding expectedResponse = 2046 Finding.newBuilder() 2047 .setName( 2048 FindingName.ofOrganizationSourceFindingName( 2049 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2050 .toString()) 2051 .setParent("parent-995424086") 2052 .setResourceName("resourceName-384566343") 2053 .setCategory("category50511102") 2054 .setExternalUri("externalUri-1153085023") 2055 .putAllSourceProperties(new HashMap<String, Value>()) 2056 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2057 .setEventTime(Timestamp.newBuilder().build()) 2058 .setCreateTime(Timestamp.newBuilder().build()) 2059 .setCanonicalName("canonicalName2122381727") 2060 .build(); 2061 mockService.addResponse(expectedResponse); 2062 2063 String name = "organizations/organization-9392/sources/source-9392/findings/finding-9392"; 2064 Finding.State state = Finding.State.forNumber(0); 2065 Timestamp startTime = Timestamp.newBuilder().build(); 2066 2067 Finding actualResponse = client.setFindingState(name, state, startTime); 2068 Assert.assertEquals(expectedResponse, actualResponse); 2069 2070 List<String> actualRequests = mockService.getRequestPaths(); 2071 Assert.assertEquals(1, actualRequests.size()); 2072 2073 String apiClientHeaderKey = 2074 mockService 2075 .getRequestHeaders() 2076 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2077 .iterator() 2078 .next(); 2079 Assert.assertTrue( 2080 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2081 .matcher(apiClientHeaderKey) 2082 .matches()); 2083 } 2084 2085 @Test setFindingStateExceptionTest2()2086 public void setFindingStateExceptionTest2() throws Exception { 2087 ApiException exception = 2088 ApiExceptionFactory.createException( 2089 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2090 mockService.addException(exception); 2091 2092 try { 2093 String name = "organizations/organization-9392/sources/source-9392/findings/finding-9392"; 2094 Finding.State state = Finding.State.forNumber(0); 2095 Timestamp startTime = Timestamp.newBuilder().build(); 2096 client.setFindingState(name, state, startTime); 2097 Assert.fail("No exception raised"); 2098 } catch (InvalidArgumentException e) { 2099 // Expected exception. 2100 } 2101 } 2102 2103 @Test setIamPolicyTest()2104 public void setIamPolicyTest() throws Exception { 2105 Policy expectedResponse = 2106 Policy.newBuilder() 2107 .setVersion(351608024) 2108 .addAllBindings(new ArrayList<Binding>()) 2109 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 2110 .setEtag(ByteString.EMPTY) 2111 .build(); 2112 mockService.addResponse(expectedResponse); 2113 2114 ResourceName resource = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 2115 Policy policy = Policy.newBuilder().build(); 2116 2117 Policy actualResponse = client.setIamPolicy(resource, policy); 2118 Assert.assertEquals(expectedResponse, actualResponse); 2119 2120 List<String> actualRequests = mockService.getRequestPaths(); 2121 Assert.assertEquals(1, actualRequests.size()); 2122 2123 String apiClientHeaderKey = 2124 mockService 2125 .getRequestHeaders() 2126 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2127 .iterator() 2128 .next(); 2129 Assert.assertTrue( 2130 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2131 .matcher(apiClientHeaderKey) 2132 .matches()); 2133 } 2134 2135 @Test setIamPolicyExceptionTest()2136 public void setIamPolicyExceptionTest() throws Exception { 2137 ApiException exception = 2138 ApiExceptionFactory.createException( 2139 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2140 mockService.addException(exception); 2141 2142 try { 2143 ResourceName resource = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 2144 Policy policy = Policy.newBuilder().build(); 2145 client.setIamPolicy(resource, policy); 2146 Assert.fail("No exception raised"); 2147 } catch (InvalidArgumentException e) { 2148 // Expected exception. 2149 } 2150 } 2151 2152 @Test setIamPolicyTest2()2153 public void setIamPolicyTest2() throws Exception { 2154 Policy expectedResponse = 2155 Policy.newBuilder() 2156 .setVersion(351608024) 2157 .addAllBindings(new ArrayList<Binding>()) 2158 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 2159 .setEtag(ByteString.EMPTY) 2160 .build(); 2161 mockService.addResponse(expectedResponse); 2162 2163 String resource = "organizations/organization-3393/sources/source-3393"; 2164 Policy policy = Policy.newBuilder().build(); 2165 2166 Policy actualResponse = client.setIamPolicy(resource, policy); 2167 Assert.assertEquals(expectedResponse, actualResponse); 2168 2169 List<String> actualRequests = mockService.getRequestPaths(); 2170 Assert.assertEquals(1, actualRequests.size()); 2171 2172 String apiClientHeaderKey = 2173 mockService 2174 .getRequestHeaders() 2175 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2176 .iterator() 2177 .next(); 2178 Assert.assertTrue( 2179 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2180 .matcher(apiClientHeaderKey) 2181 .matches()); 2182 } 2183 2184 @Test setIamPolicyExceptionTest2()2185 public void setIamPolicyExceptionTest2() throws Exception { 2186 ApiException exception = 2187 ApiExceptionFactory.createException( 2188 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2189 mockService.addException(exception); 2190 2191 try { 2192 String resource = "organizations/organization-3393/sources/source-3393"; 2193 Policy policy = Policy.newBuilder().build(); 2194 client.setIamPolicy(resource, policy); 2195 Assert.fail("No exception raised"); 2196 } catch (InvalidArgumentException e) { 2197 // Expected exception. 2198 } 2199 } 2200 2201 @Test testIamPermissionsTest()2202 public void testIamPermissionsTest() throws Exception { 2203 TestIamPermissionsResponse expectedResponse = 2204 TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build(); 2205 mockService.addResponse(expectedResponse); 2206 2207 ResourceName resource = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 2208 List<String> permissions = new ArrayList<>(); 2209 2210 TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); 2211 Assert.assertEquals(expectedResponse, actualResponse); 2212 2213 List<String> actualRequests = mockService.getRequestPaths(); 2214 Assert.assertEquals(1, actualRequests.size()); 2215 2216 String apiClientHeaderKey = 2217 mockService 2218 .getRequestHeaders() 2219 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2220 .iterator() 2221 .next(); 2222 Assert.assertTrue( 2223 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2224 .matcher(apiClientHeaderKey) 2225 .matches()); 2226 } 2227 2228 @Test testIamPermissionsExceptionTest()2229 public void testIamPermissionsExceptionTest() throws Exception { 2230 ApiException exception = 2231 ApiExceptionFactory.createException( 2232 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2233 mockService.addException(exception); 2234 2235 try { 2236 ResourceName resource = SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]"); 2237 List<String> permissions = new ArrayList<>(); 2238 client.testIamPermissions(resource, permissions); 2239 Assert.fail("No exception raised"); 2240 } catch (InvalidArgumentException e) { 2241 // Expected exception. 2242 } 2243 } 2244 2245 @Test testIamPermissionsTest2()2246 public void testIamPermissionsTest2() throws Exception { 2247 TestIamPermissionsResponse expectedResponse = 2248 TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build(); 2249 mockService.addResponse(expectedResponse); 2250 2251 String resource = "organizations/organization-3393/sources/source-3393"; 2252 List<String> permissions = new ArrayList<>(); 2253 2254 TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions); 2255 Assert.assertEquals(expectedResponse, actualResponse); 2256 2257 List<String> actualRequests = mockService.getRequestPaths(); 2258 Assert.assertEquals(1, actualRequests.size()); 2259 2260 String apiClientHeaderKey = 2261 mockService 2262 .getRequestHeaders() 2263 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2264 .iterator() 2265 .next(); 2266 Assert.assertTrue( 2267 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2268 .matcher(apiClientHeaderKey) 2269 .matches()); 2270 } 2271 2272 @Test testIamPermissionsExceptionTest2()2273 public void testIamPermissionsExceptionTest2() throws Exception { 2274 ApiException exception = 2275 ApiExceptionFactory.createException( 2276 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2277 mockService.addException(exception); 2278 2279 try { 2280 String resource = "organizations/organization-3393/sources/source-3393"; 2281 List<String> permissions = new ArrayList<>(); 2282 client.testIamPermissions(resource, permissions); 2283 Assert.fail("No exception raised"); 2284 } catch (InvalidArgumentException e) { 2285 // Expected exception. 2286 } 2287 } 2288 2289 @Test updateFindingTest()2290 public void updateFindingTest() throws Exception { 2291 Finding expectedResponse = 2292 Finding.newBuilder() 2293 .setName( 2294 FindingName.ofOrganizationSourceFindingName( 2295 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2296 .toString()) 2297 .setParent("parent-995424086") 2298 .setResourceName("resourceName-384566343") 2299 .setCategory("category50511102") 2300 .setExternalUri("externalUri-1153085023") 2301 .putAllSourceProperties(new HashMap<String, Value>()) 2302 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2303 .setEventTime(Timestamp.newBuilder().build()) 2304 .setCreateTime(Timestamp.newBuilder().build()) 2305 .setCanonicalName("canonicalName2122381727") 2306 .build(); 2307 mockService.addResponse(expectedResponse); 2308 2309 Finding finding = 2310 Finding.newBuilder() 2311 .setName( 2312 FindingName.ofOrganizationSourceFindingName( 2313 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2314 .toString()) 2315 .setParent("parent-995424086") 2316 .setResourceName("resourceName-384566343") 2317 .setCategory("category50511102") 2318 .setExternalUri("externalUri-1153085023") 2319 .putAllSourceProperties(new HashMap<String, Value>()) 2320 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2321 .setEventTime(Timestamp.newBuilder().build()) 2322 .setCreateTime(Timestamp.newBuilder().build()) 2323 .setCanonicalName("canonicalName2122381727") 2324 .build(); 2325 2326 Finding actualResponse = client.updateFinding(finding); 2327 Assert.assertEquals(expectedResponse, actualResponse); 2328 2329 List<String> actualRequests = mockService.getRequestPaths(); 2330 Assert.assertEquals(1, actualRequests.size()); 2331 2332 String apiClientHeaderKey = 2333 mockService 2334 .getRequestHeaders() 2335 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2336 .iterator() 2337 .next(); 2338 Assert.assertTrue( 2339 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2340 .matcher(apiClientHeaderKey) 2341 .matches()); 2342 } 2343 2344 @Test updateFindingExceptionTest()2345 public void updateFindingExceptionTest() throws Exception { 2346 ApiException exception = 2347 ApiExceptionFactory.createException( 2348 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2349 mockService.addException(exception); 2350 2351 try { 2352 Finding finding = 2353 Finding.newBuilder() 2354 .setName( 2355 FindingName.ofOrganizationSourceFindingName( 2356 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2357 .toString()) 2358 .setParent("parent-995424086") 2359 .setResourceName("resourceName-384566343") 2360 .setCategory("category50511102") 2361 .setExternalUri("externalUri-1153085023") 2362 .putAllSourceProperties(new HashMap<String, Value>()) 2363 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2364 .setEventTime(Timestamp.newBuilder().build()) 2365 .setCreateTime(Timestamp.newBuilder().build()) 2366 .setCanonicalName("canonicalName2122381727") 2367 .build(); 2368 client.updateFinding(finding); 2369 Assert.fail("No exception raised"); 2370 } catch (InvalidArgumentException e) { 2371 // Expected exception. 2372 } 2373 } 2374 2375 @Test updateFindingTest2()2376 public void updateFindingTest2() throws Exception { 2377 Finding expectedResponse = 2378 Finding.newBuilder() 2379 .setName( 2380 FindingName.ofOrganizationSourceFindingName( 2381 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2382 .toString()) 2383 .setParent("parent-995424086") 2384 .setResourceName("resourceName-384566343") 2385 .setCategory("category50511102") 2386 .setExternalUri("externalUri-1153085023") 2387 .putAllSourceProperties(new HashMap<String, Value>()) 2388 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2389 .setEventTime(Timestamp.newBuilder().build()) 2390 .setCreateTime(Timestamp.newBuilder().build()) 2391 .setCanonicalName("canonicalName2122381727") 2392 .build(); 2393 mockService.addResponse(expectedResponse); 2394 2395 Finding finding = 2396 Finding.newBuilder() 2397 .setName( 2398 FindingName.ofOrganizationSourceFindingName( 2399 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2400 .toString()) 2401 .setParent("parent-995424086") 2402 .setResourceName("resourceName-384566343") 2403 .setCategory("category50511102") 2404 .setExternalUri("externalUri-1153085023") 2405 .putAllSourceProperties(new HashMap<String, Value>()) 2406 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2407 .setEventTime(Timestamp.newBuilder().build()) 2408 .setCreateTime(Timestamp.newBuilder().build()) 2409 .setCanonicalName("canonicalName2122381727") 2410 .build(); 2411 FieldMask updateMask = FieldMask.newBuilder().build(); 2412 2413 Finding actualResponse = client.updateFinding(finding, updateMask); 2414 Assert.assertEquals(expectedResponse, actualResponse); 2415 2416 List<String> actualRequests = mockService.getRequestPaths(); 2417 Assert.assertEquals(1, actualRequests.size()); 2418 2419 String apiClientHeaderKey = 2420 mockService 2421 .getRequestHeaders() 2422 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2423 .iterator() 2424 .next(); 2425 Assert.assertTrue( 2426 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2427 .matcher(apiClientHeaderKey) 2428 .matches()); 2429 } 2430 2431 @Test updateFindingExceptionTest2()2432 public void updateFindingExceptionTest2() throws Exception { 2433 ApiException exception = 2434 ApiExceptionFactory.createException( 2435 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2436 mockService.addException(exception); 2437 2438 try { 2439 Finding finding = 2440 Finding.newBuilder() 2441 .setName( 2442 FindingName.ofOrganizationSourceFindingName( 2443 "[ORGANIZATION]", "[SOURCE]", "[FINDING]") 2444 .toString()) 2445 .setParent("parent-995424086") 2446 .setResourceName("resourceName-384566343") 2447 .setCategory("category50511102") 2448 .setExternalUri("externalUri-1153085023") 2449 .putAllSourceProperties(new HashMap<String, Value>()) 2450 .setSecurityMarks(SecurityMarks.newBuilder().build()) 2451 .setEventTime(Timestamp.newBuilder().build()) 2452 .setCreateTime(Timestamp.newBuilder().build()) 2453 .setCanonicalName("canonicalName2122381727") 2454 .build(); 2455 FieldMask updateMask = FieldMask.newBuilder().build(); 2456 client.updateFinding(finding, updateMask); 2457 Assert.fail("No exception raised"); 2458 } catch (InvalidArgumentException e) { 2459 // Expected exception. 2460 } 2461 } 2462 2463 @Test updateNotificationConfigTest()2464 public void updateNotificationConfigTest() throws Exception { 2465 NotificationConfig expectedResponse = 2466 NotificationConfig.newBuilder() 2467 .setName( 2468 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 2469 .setDescription("description-1724546052") 2470 .setPubsubTopic("pubsubTopic255880396") 2471 .setServiceAccount("serviceAccount1079137720") 2472 .build(); 2473 mockService.addResponse(expectedResponse); 2474 2475 NotificationConfig notificationConfig = 2476 NotificationConfig.newBuilder() 2477 .setName( 2478 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 2479 .setDescription("description-1724546052") 2480 .setPubsubTopic("pubsubTopic255880396") 2481 .setServiceAccount("serviceAccount1079137720") 2482 .build(); 2483 2484 NotificationConfig actualResponse = client.updateNotificationConfig(notificationConfig); 2485 Assert.assertEquals(expectedResponse, actualResponse); 2486 2487 List<String> actualRequests = mockService.getRequestPaths(); 2488 Assert.assertEquals(1, actualRequests.size()); 2489 2490 String apiClientHeaderKey = 2491 mockService 2492 .getRequestHeaders() 2493 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2494 .iterator() 2495 .next(); 2496 Assert.assertTrue( 2497 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2498 .matcher(apiClientHeaderKey) 2499 .matches()); 2500 } 2501 2502 @Test updateNotificationConfigExceptionTest()2503 public void updateNotificationConfigExceptionTest() throws Exception { 2504 ApiException exception = 2505 ApiExceptionFactory.createException( 2506 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2507 mockService.addException(exception); 2508 2509 try { 2510 NotificationConfig notificationConfig = 2511 NotificationConfig.newBuilder() 2512 .setName( 2513 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 2514 .setDescription("description-1724546052") 2515 .setPubsubTopic("pubsubTopic255880396") 2516 .setServiceAccount("serviceAccount1079137720") 2517 .build(); 2518 client.updateNotificationConfig(notificationConfig); 2519 Assert.fail("No exception raised"); 2520 } catch (InvalidArgumentException e) { 2521 // Expected exception. 2522 } 2523 } 2524 2525 @Test updateNotificationConfigTest2()2526 public void updateNotificationConfigTest2() throws Exception { 2527 NotificationConfig expectedResponse = 2528 NotificationConfig.newBuilder() 2529 .setName( 2530 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 2531 .setDescription("description-1724546052") 2532 .setPubsubTopic("pubsubTopic255880396") 2533 .setServiceAccount("serviceAccount1079137720") 2534 .build(); 2535 mockService.addResponse(expectedResponse); 2536 2537 NotificationConfig notificationConfig = 2538 NotificationConfig.newBuilder() 2539 .setName( 2540 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 2541 .setDescription("description-1724546052") 2542 .setPubsubTopic("pubsubTopic255880396") 2543 .setServiceAccount("serviceAccount1079137720") 2544 .build(); 2545 FieldMask updateMask = FieldMask.newBuilder().build(); 2546 2547 NotificationConfig actualResponse = 2548 client.updateNotificationConfig(notificationConfig, updateMask); 2549 Assert.assertEquals(expectedResponse, actualResponse); 2550 2551 List<String> actualRequests = mockService.getRequestPaths(); 2552 Assert.assertEquals(1, actualRequests.size()); 2553 2554 String apiClientHeaderKey = 2555 mockService 2556 .getRequestHeaders() 2557 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2558 .iterator() 2559 .next(); 2560 Assert.assertTrue( 2561 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2562 .matcher(apiClientHeaderKey) 2563 .matches()); 2564 } 2565 2566 @Test updateNotificationConfigExceptionTest2()2567 public void updateNotificationConfigExceptionTest2() throws Exception { 2568 ApiException exception = 2569 ApiExceptionFactory.createException( 2570 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2571 mockService.addException(exception); 2572 2573 try { 2574 NotificationConfig notificationConfig = 2575 NotificationConfig.newBuilder() 2576 .setName( 2577 NotificationConfigName.of("[ORGANIZATION]", "[NOTIFICATION_CONFIG]").toString()) 2578 .setDescription("description-1724546052") 2579 .setPubsubTopic("pubsubTopic255880396") 2580 .setServiceAccount("serviceAccount1079137720") 2581 .build(); 2582 FieldMask updateMask = FieldMask.newBuilder().build(); 2583 client.updateNotificationConfig(notificationConfig, updateMask); 2584 Assert.fail("No exception raised"); 2585 } catch (InvalidArgumentException e) { 2586 // Expected exception. 2587 } 2588 } 2589 2590 @Test updateOrganizationSettingsTest()2591 public void updateOrganizationSettingsTest() throws Exception { 2592 OrganizationSettings expectedResponse = 2593 OrganizationSettings.newBuilder() 2594 .setName(OrganizationSettingsName.of("[ORGANIZATION]").toString()) 2595 .setEnableAssetDiscovery(true) 2596 .setAssetDiscoveryConfig(OrganizationSettings.AssetDiscoveryConfig.newBuilder().build()) 2597 .build(); 2598 mockService.addResponse(expectedResponse); 2599 2600 OrganizationSettings organizationSettings = 2601 OrganizationSettings.newBuilder() 2602 .setName(OrganizationSettingsName.of("[ORGANIZATION]").toString()) 2603 .setEnableAssetDiscovery(true) 2604 .setAssetDiscoveryConfig(OrganizationSettings.AssetDiscoveryConfig.newBuilder().build()) 2605 .build(); 2606 2607 OrganizationSettings actualResponse = client.updateOrganizationSettings(organizationSettings); 2608 Assert.assertEquals(expectedResponse, actualResponse); 2609 2610 List<String> actualRequests = mockService.getRequestPaths(); 2611 Assert.assertEquals(1, actualRequests.size()); 2612 2613 String apiClientHeaderKey = 2614 mockService 2615 .getRequestHeaders() 2616 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2617 .iterator() 2618 .next(); 2619 Assert.assertTrue( 2620 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2621 .matcher(apiClientHeaderKey) 2622 .matches()); 2623 } 2624 2625 @Test updateOrganizationSettingsExceptionTest()2626 public void updateOrganizationSettingsExceptionTest() throws Exception { 2627 ApiException exception = 2628 ApiExceptionFactory.createException( 2629 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2630 mockService.addException(exception); 2631 2632 try { 2633 OrganizationSettings organizationSettings = 2634 OrganizationSettings.newBuilder() 2635 .setName(OrganizationSettingsName.of("[ORGANIZATION]").toString()) 2636 .setEnableAssetDiscovery(true) 2637 .setAssetDiscoveryConfig( 2638 OrganizationSettings.AssetDiscoveryConfig.newBuilder().build()) 2639 .build(); 2640 client.updateOrganizationSettings(organizationSettings); 2641 Assert.fail("No exception raised"); 2642 } catch (InvalidArgumentException e) { 2643 // Expected exception. 2644 } 2645 } 2646 2647 @Test updateSourceTest()2648 public void updateSourceTest() throws Exception { 2649 Source expectedResponse = 2650 Source.newBuilder() 2651 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 2652 .setDisplayName("displayName1714148973") 2653 .setDescription("description-1724546052") 2654 .setCanonicalName("canonicalName2122381727") 2655 .build(); 2656 mockService.addResponse(expectedResponse); 2657 2658 Source source = 2659 Source.newBuilder() 2660 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 2661 .setDisplayName("displayName1714148973") 2662 .setDescription("description-1724546052") 2663 .setCanonicalName("canonicalName2122381727") 2664 .build(); 2665 2666 Source actualResponse = client.updateSource(source); 2667 Assert.assertEquals(expectedResponse, actualResponse); 2668 2669 List<String> actualRequests = mockService.getRequestPaths(); 2670 Assert.assertEquals(1, actualRequests.size()); 2671 2672 String apiClientHeaderKey = 2673 mockService 2674 .getRequestHeaders() 2675 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2676 .iterator() 2677 .next(); 2678 Assert.assertTrue( 2679 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2680 .matcher(apiClientHeaderKey) 2681 .matches()); 2682 } 2683 2684 @Test updateSourceExceptionTest()2685 public void updateSourceExceptionTest() throws Exception { 2686 ApiException exception = 2687 ApiExceptionFactory.createException( 2688 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2689 mockService.addException(exception); 2690 2691 try { 2692 Source source = 2693 Source.newBuilder() 2694 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 2695 .setDisplayName("displayName1714148973") 2696 .setDescription("description-1724546052") 2697 .setCanonicalName("canonicalName2122381727") 2698 .build(); 2699 client.updateSource(source); 2700 Assert.fail("No exception raised"); 2701 } catch (InvalidArgumentException e) { 2702 // Expected exception. 2703 } 2704 } 2705 2706 @Test updateSourceTest2()2707 public void updateSourceTest2() throws Exception { 2708 Source expectedResponse = 2709 Source.newBuilder() 2710 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 2711 .setDisplayName("displayName1714148973") 2712 .setDescription("description-1724546052") 2713 .setCanonicalName("canonicalName2122381727") 2714 .build(); 2715 mockService.addResponse(expectedResponse); 2716 2717 Source source = 2718 Source.newBuilder() 2719 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 2720 .setDisplayName("displayName1714148973") 2721 .setDescription("description-1724546052") 2722 .setCanonicalName("canonicalName2122381727") 2723 .build(); 2724 FieldMask updateMask = FieldMask.newBuilder().build(); 2725 2726 Source actualResponse = client.updateSource(source, updateMask); 2727 Assert.assertEquals(expectedResponse, actualResponse); 2728 2729 List<String> actualRequests = mockService.getRequestPaths(); 2730 Assert.assertEquals(1, actualRequests.size()); 2731 2732 String apiClientHeaderKey = 2733 mockService 2734 .getRequestHeaders() 2735 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2736 .iterator() 2737 .next(); 2738 Assert.assertTrue( 2739 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2740 .matcher(apiClientHeaderKey) 2741 .matches()); 2742 } 2743 2744 @Test updateSourceExceptionTest2()2745 public void updateSourceExceptionTest2() throws Exception { 2746 ApiException exception = 2747 ApiExceptionFactory.createException( 2748 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2749 mockService.addException(exception); 2750 2751 try { 2752 Source source = 2753 Source.newBuilder() 2754 .setName(SourceName.ofOrganizationSourceName("[ORGANIZATION]", "[SOURCE]").toString()) 2755 .setDisplayName("displayName1714148973") 2756 .setDescription("description-1724546052") 2757 .setCanonicalName("canonicalName2122381727") 2758 .build(); 2759 FieldMask updateMask = FieldMask.newBuilder().build(); 2760 client.updateSource(source, updateMask); 2761 Assert.fail("No exception raised"); 2762 } catch (InvalidArgumentException e) { 2763 // Expected exception. 2764 } 2765 } 2766 2767 @Test updateSecurityMarksTest()2768 public void updateSecurityMarksTest() throws Exception { 2769 SecurityMarks expectedResponse = 2770 SecurityMarks.newBuilder() 2771 .setName("name3373707") 2772 .putAllMarks(new HashMap<String, String>()) 2773 .setCanonicalName("canonicalName2122381727") 2774 .build(); 2775 mockService.addResponse(expectedResponse); 2776 2777 SecurityMarks securityMarks = 2778 SecurityMarks.newBuilder() 2779 .setName("organizations/organization-5924/assets/asset-5924/securityMarks") 2780 .putAllMarks(new HashMap<String, String>()) 2781 .setCanonicalName("canonicalName2122381727") 2782 .build(); 2783 2784 SecurityMarks actualResponse = client.updateSecurityMarks(securityMarks); 2785 Assert.assertEquals(expectedResponse, actualResponse); 2786 2787 List<String> actualRequests = mockService.getRequestPaths(); 2788 Assert.assertEquals(1, actualRequests.size()); 2789 2790 String apiClientHeaderKey = 2791 mockService 2792 .getRequestHeaders() 2793 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2794 .iterator() 2795 .next(); 2796 Assert.assertTrue( 2797 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2798 .matcher(apiClientHeaderKey) 2799 .matches()); 2800 } 2801 2802 @Test updateSecurityMarksExceptionTest()2803 public void updateSecurityMarksExceptionTest() throws Exception { 2804 ApiException exception = 2805 ApiExceptionFactory.createException( 2806 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2807 mockService.addException(exception); 2808 2809 try { 2810 SecurityMarks securityMarks = 2811 SecurityMarks.newBuilder() 2812 .setName("organizations/organization-5924/assets/asset-5924/securityMarks") 2813 .putAllMarks(new HashMap<String, String>()) 2814 .setCanonicalName("canonicalName2122381727") 2815 .build(); 2816 client.updateSecurityMarks(securityMarks); 2817 Assert.fail("No exception raised"); 2818 } catch (InvalidArgumentException e) { 2819 // Expected exception. 2820 } 2821 } 2822 2823 @Test updateSecurityMarksTest2()2824 public void updateSecurityMarksTest2() throws Exception { 2825 SecurityMarks expectedResponse = 2826 SecurityMarks.newBuilder() 2827 .setName("name3373707") 2828 .putAllMarks(new HashMap<String, String>()) 2829 .setCanonicalName("canonicalName2122381727") 2830 .build(); 2831 mockService.addResponse(expectedResponse); 2832 2833 SecurityMarks securityMarks = 2834 SecurityMarks.newBuilder() 2835 .setName("organizations/organization-5924/assets/asset-5924/securityMarks") 2836 .putAllMarks(new HashMap<String, String>()) 2837 .setCanonicalName("canonicalName2122381727") 2838 .build(); 2839 FieldMask updateMask = FieldMask.newBuilder().build(); 2840 2841 SecurityMarks actualResponse = client.updateSecurityMarks(securityMarks, updateMask); 2842 Assert.assertEquals(expectedResponse, actualResponse); 2843 2844 List<String> actualRequests = mockService.getRequestPaths(); 2845 Assert.assertEquals(1, actualRequests.size()); 2846 2847 String apiClientHeaderKey = 2848 mockService 2849 .getRequestHeaders() 2850 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 2851 .iterator() 2852 .next(); 2853 Assert.assertTrue( 2854 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 2855 .matcher(apiClientHeaderKey) 2856 .matches()); 2857 } 2858 2859 @Test updateSecurityMarksExceptionTest2()2860 public void updateSecurityMarksExceptionTest2() throws Exception { 2861 ApiException exception = 2862 ApiExceptionFactory.createException( 2863 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 2864 mockService.addException(exception); 2865 2866 try { 2867 SecurityMarks securityMarks = 2868 SecurityMarks.newBuilder() 2869 .setName("organizations/organization-5924/assets/asset-5924/securityMarks") 2870 .putAllMarks(new HashMap<String, String>()) 2871 .setCanonicalName("canonicalName2122381727") 2872 .build(); 2873 FieldMask updateMask = FieldMask.newBuilder().build(); 2874 client.updateSecurityMarks(securityMarks, updateMask); 2875 Assert.fail("No exception raised"); 2876 } catch (InvalidArgumentException e) { 2877 // Expected exception. 2878 } 2879 } 2880 } 2881