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.osconfig.v1beta; 18 19 import static com.google.cloud.osconfig.v1beta.OsConfigServiceClient.ListGuestPoliciesPagedResponse; 20 import static com.google.cloud.osconfig.v1beta.OsConfigServiceClient.ListPatchDeploymentsPagedResponse; 21 import static com.google.cloud.osconfig.v1beta.OsConfigServiceClient.ListPatchJobInstanceDetailsPagedResponse; 22 import static com.google.cloud.osconfig.v1beta.OsConfigServiceClient.ListPatchJobsPagedResponse; 23 24 import com.google.api.gax.core.NoCredentialsProvider; 25 import com.google.api.gax.httpjson.GaxHttpJsonProperties; 26 import com.google.api.gax.httpjson.testing.MockHttpService; 27 import com.google.api.gax.rpc.ApiClientHeaderProvider; 28 import com.google.api.gax.rpc.ApiException; 29 import com.google.api.gax.rpc.ApiExceptionFactory; 30 import com.google.api.gax.rpc.InvalidArgumentException; 31 import com.google.api.gax.rpc.StatusCode; 32 import com.google.api.gax.rpc.testing.FakeStatusCode; 33 import com.google.cloud.osconfig.v1beta.stub.HttpJsonOsConfigServiceStub; 34 import com.google.common.collect.Lists; 35 import com.google.protobuf.Duration; 36 import com.google.protobuf.Empty; 37 import com.google.protobuf.FieldMask; 38 import com.google.protobuf.Timestamp; 39 import java.io.IOException; 40 import java.util.ArrayList; 41 import java.util.Arrays; 42 import java.util.List; 43 import javax.annotation.Generated; 44 import org.junit.After; 45 import org.junit.AfterClass; 46 import org.junit.Assert; 47 import org.junit.Before; 48 import org.junit.BeforeClass; 49 import org.junit.Test; 50 51 @Generated("by gapic-generator-java") 52 public class OsConfigServiceClientHttpJsonTest { 53 private static MockHttpService mockService; 54 private static OsConfigServiceClient client; 55 56 @BeforeClass startStaticServer()57 public static void startStaticServer() throws IOException { 58 mockService = 59 new MockHttpService( 60 HttpJsonOsConfigServiceStub.getMethodDescriptors(), 61 OsConfigServiceSettings.getDefaultEndpoint()); 62 OsConfigServiceSettings settings = 63 OsConfigServiceSettings.newHttpJsonBuilder() 64 .setTransportChannelProvider( 65 OsConfigServiceSettings.defaultHttpJsonTransportProviderBuilder() 66 .setHttpTransport(mockService) 67 .build()) 68 .setCredentialsProvider(NoCredentialsProvider.create()) 69 .build(); 70 client = OsConfigServiceClient.create(settings); 71 } 72 73 @AfterClass stopServer()74 public static void stopServer() { 75 client.close(); 76 } 77 78 @Before setUp()79 public void setUp() {} 80 81 @After tearDown()82 public void tearDown() throws Exception { 83 mockService.reset(); 84 } 85 86 @Test executePatchJobTest()87 public void executePatchJobTest() throws Exception { 88 PatchJobs.PatchJob expectedResponse = 89 PatchJobs.PatchJob.newBuilder() 90 .setName("name3373707") 91 .setDisplayName("displayName1714148973") 92 .setDescription("description-1724546052") 93 .setCreateTime(Timestamp.newBuilder().build()) 94 .setUpdateTime(Timestamp.newBuilder().build()) 95 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 96 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 97 .setDuration(Duration.newBuilder().build()) 98 .setInstanceDetailsSummary( 99 PatchJobs.PatchJob.InstanceDetailsSummary.newBuilder().build()) 100 .setDryRun(true) 101 .setErrorMessage("errorMessage1203236063") 102 .setPercentComplete(-1960969229) 103 .setPatchDeployment("patchDeployment1500445997") 104 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 105 .build(); 106 mockService.addResponse(expectedResponse); 107 108 PatchJobs.ExecutePatchJobRequest request = 109 PatchJobs.ExecutePatchJobRequest.newBuilder() 110 .setParent("projects/project-2353") 111 .setDescription("description-1724546052") 112 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 113 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 114 .setDuration(Duration.newBuilder().build()) 115 .setDryRun(true) 116 .setDisplayName("displayName1714148973") 117 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 118 .build(); 119 120 PatchJobs.PatchJob actualResponse = client.executePatchJob(request); 121 Assert.assertEquals(expectedResponse, actualResponse); 122 123 List<String> actualRequests = mockService.getRequestPaths(); 124 Assert.assertEquals(1, actualRequests.size()); 125 126 String apiClientHeaderKey = 127 mockService 128 .getRequestHeaders() 129 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 130 .iterator() 131 .next(); 132 Assert.assertTrue( 133 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 134 .matcher(apiClientHeaderKey) 135 .matches()); 136 } 137 138 @Test executePatchJobExceptionTest()139 public void executePatchJobExceptionTest() throws Exception { 140 ApiException exception = 141 ApiExceptionFactory.createException( 142 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 143 mockService.addException(exception); 144 145 try { 146 PatchJobs.ExecutePatchJobRequest request = 147 PatchJobs.ExecutePatchJobRequest.newBuilder() 148 .setParent("projects/project-2353") 149 .setDescription("description-1724546052") 150 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 151 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 152 .setDuration(Duration.newBuilder().build()) 153 .setDryRun(true) 154 .setDisplayName("displayName1714148973") 155 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 156 .build(); 157 client.executePatchJob(request); 158 Assert.fail("No exception raised"); 159 } catch (InvalidArgumentException e) { 160 // Expected exception. 161 } 162 } 163 164 @Test getPatchJobTest()165 public void getPatchJobTest() throws Exception { 166 PatchJobs.PatchJob expectedResponse = 167 PatchJobs.PatchJob.newBuilder() 168 .setName("name3373707") 169 .setDisplayName("displayName1714148973") 170 .setDescription("description-1724546052") 171 .setCreateTime(Timestamp.newBuilder().build()) 172 .setUpdateTime(Timestamp.newBuilder().build()) 173 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 174 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 175 .setDuration(Duration.newBuilder().build()) 176 .setInstanceDetailsSummary( 177 PatchJobs.PatchJob.InstanceDetailsSummary.newBuilder().build()) 178 .setDryRun(true) 179 .setErrorMessage("errorMessage1203236063") 180 .setPercentComplete(-1960969229) 181 .setPatchDeployment("patchDeployment1500445997") 182 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 183 .build(); 184 mockService.addResponse(expectedResponse); 185 186 PatchJobs.GetPatchJobRequest request = 187 PatchJobs.GetPatchJobRequest.newBuilder() 188 .setName("projects/project-3014/patchJobs/patchJob-3014") 189 .build(); 190 191 PatchJobs.PatchJob actualResponse = client.getPatchJob(request); 192 Assert.assertEquals(expectedResponse, actualResponse); 193 194 List<String> actualRequests = mockService.getRequestPaths(); 195 Assert.assertEquals(1, actualRequests.size()); 196 197 String apiClientHeaderKey = 198 mockService 199 .getRequestHeaders() 200 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 201 .iterator() 202 .next(); 203 Assert.assertTrue( 204 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 205 .matcher(apiClientHeaderKey) 206 .matches()); 207 } 208 209 @Test getPatchJobExceptionTest()210 public void getPatchJobExceptionTest() throws Exception { 211 ApiException exception = 212 ApiExceptionFactory.createException( 213 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 214 mockService.addException(exception); 215 216 try { 217 PatchJobs.GetPatchJobRequest request = 218 PatchJobs.GetPatchJobRequest.newBuilder() 219 .setName("projects/project-3014/patchJobs/patchJob-3014") 220 .build(); 221 client.getPatchJob(request); 222 Assert.fail("No exception raised"); 223 } catch (InvalidArgumentException e) { 224 // Expected exception. 225 } 226 } 227 228 @Test cancelPatchJobTest()229 public void cancelPatchJobTest() throws Exception { 230 PatchJobs.PatchJob expectedResponse = 231 PatchJobs.PatchJob.newBuilder() 232 .setName("name3373707") 233 .setDisplayName("displayName1714148973") 234 .setDescription("description-1724546052") 235 .setCreateTime(Timestamp.newBuilder().build()) 236 .setUpdateTime(Timestamp.newBuilder().build()) 237 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 238 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 239 .setDuration(Duration.newBuilder().build()) 240 .setInstanceDetailsSummary( 241 PatchJobs.PatchJob.InstanceDetailsSummary.newBuilder().build()) 242 .setDryRun(true) 243 .setErrorMessage("errorMessage1203236063") 244 .setPercentComplete(-1960969229) 245 .setPatchDeployment("patchDeployment1500445997") 246 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 247 .build(); 248 mockService.addResponse(expectedResponse); 249 250 PatchJobs.CancelPatchJobRequest request = 251 PatchJobs.CancelPatchJobRequest.newBuilder() 252 .setName("projects/project-3014/patchJobs/patchJob-3014") 253 .build(); 254 255 PatchJobs.PatchJob actualResponse = client.cancelPatchJob(request); 256 Assert.assertEquals(expectedResponse, actualResponse); 257 258 List<String> actualRequests = mockService.getRequestPaths(); 259 Assert.assertEquals(1, actualRequests.size()); 260 261 String apiClientHeaderKey = 262 mockService 263 .getRequestHeaders() 264 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 265 .iterator() 266 .next(); 267 Assert.assertTrue( 268 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 269 .matcher(apiClientHeaderKey) 270 .matches()); 271 } 272 273 @Test cancelPatchJobExceptionTest()274 public void cancelPatchJobExceptionTest() throws Exception { 275 ApiException exception = 276 ApiExceptionFactory.createException( 277 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 278 mockService.addException(exception); 279 280 try { 281 PatchJobs.CancelPatchJobRequest request = 282 PatchJobs.CancelPatchJobRequest.newBuilder() 283 .setName("projects/project-3014/patchJobs/patchJob-3014") 284 .build(); 285 client.cancelPatchJob(request); 286 Assert.fail("No exception raised"); 287 } catch (InvalidArgumentException e) { 288 // Expected exception. 289 } 290 } 291 292 @Test listPatchJobsTest()293 public void listPatchJobsTest() throws Exception { 294 PatchJobs.PatchJob responsesElement = PatchJobs.PatchJob.newBuilder().build(); 295 PatchJobs.ListPatchJobsResponse expectedResponse = 296 PatchJobs.ListPatchJobsResponse.newBuilder() 297 .setNextPageToken("") 298 .addAllPatchJobs(Arrays.asList(responsesElement)) 299 .build(); 300 mockService.addResponse(expectedResponse); 301 302 PatchJobs.ListPatchJobsRequest request = 303 PatchJobs.ListPatchJobsRequest.newBuilder() 304 .setParent("projects/project-2353") 305 .setPageSize(883849137) 306 .setPageToken("pageToken873572522") 307 .setFilter("filter-1274492040") 308 .build(); 309 310 ListPatchJobsPagedResponse pagedListResponse = client.listPatchJobs(request); 311 312 List<PatchJobs.PatchJob> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 313 314 Assert.assertEquals(1, resources.size()); 315 Assert.assertEquals(expectedResponse.getPatchJobsList().get(0), resources.get(0)); 316 317 List<String> actualRequests = mockService.getRequestPaths(); 318 Assert.assertEquals(1, actualRequests.size()); 319 320 String apiClientHeaderKey = 321 mockService 322 .getRequestHeaders() 323 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 324 .iterator() 325 .next(); 326 Assert.assertTrue( 327 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 328 .matcher(apiClientHeaderKey) 329 .matches()); 330 } 331 332 @Test listPatchJobsExceptionTest()333 public void listPatchJobsExceptionTest() throws Exception { 334 ApiException exception = 335 ApiExceptionFactory.createException( 336 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 337 mockService.addException(exception); 338 339 try { 340 PatchJobs.ListPatchJobsRequest request = 341 PatchJobs.ListPatchJobsRequest.newBuilder() 342 .setParent("projects/project-2353") 343 .setPageSize(883849137) 344 .setPageToken("pageToken873572522") 345 .setFilter("filter-1274492040") 346 .build(); 347 client.listPatchJobs(request); 348 Assert.fail("No exception raised"); 349 } catch (InvalidArgumentException e) { 350 // Expected exception. 351 } 352 } 353 354 @Test listPatchJobInstanceDetailsTest()355 public void listPatchJobInstanceDetailsTest() throws Exception { 356 PatchJobs.PatchJobInstanceDetails responsesElement = 357 PatchJobs.PatchJobInstanceDetails.newBuilder().build(); 358 PatchJobs.ListPatchJobInstanceDetailsResponse expectedResponse = 359 PatchJobs.ListPatchJobInstanceDetailsResponse.newBuilder() 360 .setNextPageToken("") 361 .addAllPatchJobInstanceDetails(Arrays.asList(responsesElement)) 362 .build(); 363 mockService.addResponse(expectedResponse); 364 365 String parent = "projects/project-1881/patchJobs/patchJob-1881"; 366 367 ListPatchJobInstanceDetailsPagedResponse pagedListResponse = 368 client.listPatchJobInstanceDetails(parent); 369 370 List<PatchJobs.PatchJobInstanceDetails> resources = 371 Lists.newArrayList(pagedListResponse.iterateAll()); 372 373 Assert.assertEquals(1, resources.size()); 374 Assert.assertEquals(expectedResponse.getPatchJobInstanceDetailsList().get(0), resources.get(0)); 375 376 List<String> actualRequests = mockService.getRequestPaths(); 377 Assert.assertEquals(1, actualRequests.size()); 378 379 String apiClientHeaderKey = 380 mockService 381 .getRequestHeaders() 382 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 383 .iterator() 384 .next(); 385 Assert.assertTrue( 386 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 387 .matcher(apiClientHeaderKey) 388 .matches()); 389 } 390 391 @Test listPatchJobInstanceDetailsExceptionTest()392 public void listPatchJobInstanceDetailsExceptionTest() throws Exception { 393 ApiException exception = 394 ApiExceptionFactory.createException( 395 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 396 mockService.addException(exception); 397 398 try { 399 String parent = "projects/project-1881/patchJobs/patchJob-1881"; 400 client.listPatchJobInstanceDetails(parent); 401 Assert.fail("No exception raised"); 402 } catch (InvalidArgumentException e) { 403 // Expected exception. 404 } 405 } 406 407 @Test createPatchDeploymentTest()408 public void createPatchDeploymentTest() throws Exception { 409 PatchDeployments.PatchDeployment expectedResponse = 410 PatchDeployments.PatchDeployment.newBuilder() 411 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 412 .setDescription("description-1724546052") 413 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 414 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 415 .setDuration(Duration.newBuilder().build()) 416 .setCreateTime(Timestamp.newBuilder().build()) 417 .setUpdateTime(Timestamp.newBuilder().build()) 418 .setLastExecuteTime(Timestamp.newBuilder().build()) 419 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 420 .build(); 421 mockService.addResponse(expectedResponse); 422 423 PatchDeployments.CreatePatchDeploymentRequest request = 424 PatchDeployments.CreatePatchDeploymentRequest.newBuilder() 425 .setParent("projects/project-2353") 426 .setPatchDeploymentId("patchDeploymentId-1180405976") 427 .setPatchDeployment(PatchDeployments.PatchDeployment.newBuilder().build()) 428 .build(); 429 430 PatchDeployments.PatchDeployment actualResponse = client.createPatchDeployment(request); 431 Assert.assertEquals(expectedResponse, actualResponse); 432 433 List<String> actualRequests = mockService.getRequestPaths(); 434 Assert.assertEquals(1, actualRequests.size()); 435 436 String apiClientHeaderKey = 437 mockService 438 .getRequestHeaders() 439 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 440 .iterator() 441 .next(); 442 Assert.assertTrue( 443 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 444 .matcher(apiClientHeaderKey) 445 .matches()); 446 } 447 448 @Test createPatchDeploymentExceptionTest()449 public void createPatchDeploymentExceptionTest() throws Exception { 450 ApiException exception = 451 ApiExceptionFactory.createException( 452 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 453 mockService.addException(exception); 454 455 try { 456 PatchDeployments.CreatePatchDeploymentRequest request = 457 PatchDeployments.CreatePatchDeploymentRequest.newBuilder() 458 .setParent("projects/project-2353") 459 .setPatchDeploymentId("patchDeploymentId-1180405976") 460 .setPatchDeployment(PatchDeployments.PatchDeployment.newBuilder().build()) 461 .build(); 462 client.createPatchDeployment(request); 463 Assert.fail("No exception raised"); 464 } catch (InvalidArgumentException e) { 465 // Expected exception. 466 } 467 } 468 469 @Test getPatchDeploymentTest()470 public void getPatchDeploymentTest() throws Exception { 471 PatchDeployments.PatchDeployment expectedResponse = 472 PatchDeployments.PatchDeployment.newBuilder() 473 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 474 .setDescription("description-1724546052") 475 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 476 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 477 .setDuration(Duration.newBuilder().build()) 478 .setCreateTime(Timestamp.newBuilder().build()) 479 .setUpdateTime(Timestamp.newBuilder().build()) 480 .setLastExecuteTime(Timestamp.newBuilder().build()) 481 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 482 .build(); 483 mockService.addResponse(expectedResponse); 484 485 PatchDeployments.GetPatchDeploymentRequest request = 486 PatchDeployments.GetPatchDeploymentRequest.newBuilder() 487 .setName("projects/project-2608/patchDeployments/patchDeployment-2608") 488 .build(); 489 490 PatchDeployments.PatchDeployment actualResponse = client.getPatchDeployment(request); 491 Assert.assertEquals(expectedResponse, actualResponse); 492 493 List<String> actualRequests = mockService.getRequestPaths(); 494 Assert.assertEquals(1, actualRequests.size()); 495 496 String apiClientHeaderKey = 497 mockService 498 .getRequestHeaders() 499 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 500 .iterator() 501 .next(); 502 Assert.assertTrue( 503 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 504 .matcher(apiClientHeaderKey) 505 .matches()); 506 } 507 508 @Test getPatchDeploymentExceptionTest()509 public void getPatchDeploymentExceptionTest() throws Exception { 510 ApiException exception = 511 ApiExceptionFactory.createException( 512 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 513 mockService.addException(exception); 514 515 try { 516 PatchDeployments.GetPatchDeploymentRequest request = 517 PatchDeployments.GetPatchDeploymentRequest.newBuilder() 518 .setName("projects/project-2608/patchDeployments/patchDeployment-2608") 519 .build(); 520 client.getPatchDeployment(request); 521 Assert.fail("No exception raised"); 522 } catch (InvalidArgumentException e) { 523 // Expected exception. 524 } 525 } 526 527 @Test listPatchDeploymentsTest()528 public void listPatchDeploymentsTest() throws Exception { 529 PatchDeployments.PatchDeployment responsesElement = 530 PatchDeployments.PatchDeployment.newBuilder().build(); 531 PatchDeployments.ListPatchDeploymentsResponse expectedResponse = 532 PatchDeployments.ListPatchDeploymentsResponse.newBuilder() 533 .setNextPageToken("") 534 .addAllPatchDeployments(Arrays.asList(responsesElement)) 535 .build(); 536 mockService.addResponse(expectedResponse); 537 538 PatchDeployments.ListPatchDeploymentsRequest request = 539 PatchDeployments.ListPatchDeploymentsRequest.newBuilder() 540 .setParent("projects/project-2353") 541 .setPageSize(883849137) 542 .setPageToken("pageToken873572522") 543 .build(); 544 545 ListPatchDeploymentsPagedResponse pagedListResponse = client.listPatchDeployments(request); 546 547 List<PatchDeployments.PatchDeployment> resources = 548 Lists.newArrayList(pagedListResponse.iterateAll()); 549 550 Assert.assertEquals(1, resources.size()); 551 Assert.assertEquals(expectedResponse.getPatchDeploymentsList().get(0), resources.get(0)); 552 553 List<String> actualRequests = mockService.getRequestPaths(); 554 Assert.assertEquals(1, actualRequests.size()); 555 556 String apiClientHeaderKey = 557 mockService 558 .getRequestHeaders() 559 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 560 .iterator() 561 .next(); 562 Assert.assertTrue( 563 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 564 .matcher(apiClientHeaderKey) 565 .matches()); 566 } 567 568 @Test listPatchDeploymentsExceptionTest()569 public void listPatchDeploymentsExceptionTest() throws Exception { 570 ApiException exception = 571 ApiExceptionFactory.createException( 572 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 573 mockService.addException(exception); 574 575 try { 576 PatchDeployments.ListPatchDeploymentsRequest request = 577 PatchDeployments.ListPatchDeploymentsRequest.newBuilder() 578 .setParent("projects/project-2353") 579 .setPageSize(883849137) 580 .setPageToken("pageToken873572522") 581 .build(); 582 client.listPatchDeployments(request); 583 Assert.fail("No exception raised"); 584 } catch (InvalidArgumentException e) { 585 // Expected exception. 586 } 587 } 588 589 @Test deletePatchDeploymentTest()590 public void deletePatchDeploymentTest() throws Exception { 591 Empty expectedResponse = Empty.newBuilder().build(); 592 mockService.addResponse(expectedResponse); 593 594 PatchDeployments.DeletePatchDeploymentRequest request = 595 PatchDeployments.DeletePatchDeploymentRequest.newBuilder() 596 .setName("projects/project-2608/patchDeployments/patchDeployment-2608") 597 .build(); 598 599 client.deletePatchDeployment(request); 600 601 List<String> actualRequests = mockService.getRequestPaths(); 602 Assert.assertEquals(1, actualRequests.size()); 603 604 String apiClientHeaderKey = 605 mockService 606 .getRequestHeaders() 607 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 608 .iterator() 609 .next(); 610 Assert.assertTrue( 611 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 612 .matcher(apiClientHeaderKey) 613 .matches()); 614 } 615 616 @Test deletePatchDeploymentExceptionTest()617 public void deletePatchDeploymentExceptionTest() throws Exception { 618 ApiException exception = 619 ApiExceptionFactory.createException( 620 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 621 mockService.addException(exception); 622 623 try { 624 PatchDeployments.DeletePatchDeploymentRequest request = 625 PatchDeployments.DeletePatchDeploymentRequest.newBuilder() 626 .setName("projects/project-2608/patchDeployments/patchDeployment-2608") 627 .build(); 628 client.deletePatchDeployment(request); 629 Assert.fail("No exception raised"); 630 } catch (InvalidArgumentException e) { 631 // Expected exception. 632 } 633 } 634 635 @Test updatePatchDeploymentTest()636 public void updatePatchDeploymentTest() throws Exception { 637 PatchDeployments.PatchDeployment expectedResponse = 638 PatchDeployments.PatchDeployment.newBuilder() 639 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 640 .setDescription("description-1724546052") 641 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 642 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 643 .setDuration(Duration.newBuilder().build()) 644 .setCreateTime(Timestamp.newBuilder().build()) 645 .setUpdateTime(Timestamp.newBuilder().build()) 646 .setLastExecuteTime(Timestamp.newBuilder().build()) 647 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 648 .build(); 649 mockService.addResponse(expectedResponse); 650 651 PatchDeployments.PatchDeployment patchDeployment = 652 PatchDeployments.PatchDeployment.newBuilder() 653 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 654 .setDescription("description-1724546052") 655 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 656 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 657 .setDuration(Duration.newBuilder().build()) 658 .setCreateTime(Timestamp.newBuilder().build()) 659 .setUpdateTime(Timestamp.newBuilder().build()) 660 .setLastExecuteTime(Timestamp.newBuilder().build()) 661 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 662 .build(); 663 FieldMask updateMask = FieldMask.newBuilder().build(); 664 665 PatchDeployments.PatchDeployment actualResponse = 666 client.updatePatchDeployment(patchDeployment, updateMask); 667 Assert.assertEquals(expectedResponse, actualResponse); 668 669 List<String> actualRequests = mockService.getRequestPaths(); 670 Assert.assertEquals(1, actualRequests.size()); 671 672 String apiClientHeaderKey = 673 mockService 674 .getRequestHeaders() 675 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 676 .iterator() 677 .next(); 678 Assert.assertTrue( 679 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 680 .matcher(apiClientHeaderKey) 681 .matches()); 682 } 683 684 @Test updatePatchDeploymentExceptionTest()685 public void updatePatchDeploymentExceptionTest() throws Exception { 686 ApiException exception = 687 ApiExceptionFactory.createException( 688 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 689 mockService.addException(exception); 690 691 try { 692 PatchDeployments.PatchDeployment patchDeployment = 693 PatchDeployments.PatchDeployment.newBuilder() 694 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 695 .setDescription("description-1724546052") 696 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 697 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 698 .setDuration(Duration.newBuilder().build()) 699 .setCreateTime(Timestamp.newBuilder().build()) 700 .setUpdateTime(Timestamp.newBuilder().build()) 701 .setLastExecuteTime(Timestamp.newBuilder().build()) 702 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 703 .build(); 704 FieldMask updateMask = FieldMask.newBuilder().build(); 705 client.updatePatchDeployment(patchDeployment, updateMask); 706 Assert.fail("No exception raised"); 707 } catch (InvalidArgumentException e) { 708 // Expected exception. 709 } 710 } 711 712 @Test pausePatchDeploymentTest()713 public void pausePatchDeploymentTest() throws Exception { 714 PatchDeployments.PatchDeployment expectedResponse = 715 PatchDeployments.PatchDeployment.newBuilder() 716 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 717 .setDescription("description-1724546052") 718 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 719 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 720 .setDuration(Duration.newBuilder().build()) 721 .setCreateTime(Timestamp.newBuilder().build()) 722 .setUpdateTime(Timestamp.newBuilder().build()) 723 .setLastExecuteTime(Timestamp.newBuilder().build()) 724 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 725 .build(); 726 mockService.addResponse(expectedResponse); 727 728 PatchDeploymentName name = PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]"); 729 730 PatchDeployments.PatchDeployment actualResponse = client.pausePatchDeployment(name); 731 Assert.assertEquals(expectedResponse, actualResponse); 732 733 List<String> actualRequests = mockService.getRequestPaths(); 734 Assert.assertEquals(1, actualRequests.size()); 735 736 String apiClientHeaderKey = 737 mockService 738 .getRequestHeaders() 739 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 740 .iterator() 741 .next(); 742 Assert.assertTrue( 743 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 744 .matcher(apiClientHeaderKey) 745 .matches()); 746 } 747 748 @Test pausePatchDeploymentExceptionTest()749 public void pausePatchDeploymentExceptionTest() throws Exception { 750 ApiException exception = 751 ApiExceptionFactory.createException( 752 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 753 mockService.addException(exception); 754 755 try { 756 PatchDeploymentName name = PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]"); 757 client.pausePatchDeployment(name); 758 Assert.fail("No exception raised"); 759 } catch (InvalidArgumentException e) { 760 // Expected exception. 761 } 762 } 763 764 @Test pausePatchDeploymentTest2()765 public void pausePatchDeploymentTest2() throws Exception { 766 PatchDeployments.PatchDeployment expectedResponse = 767 PatchDeployments.PatchDeployment.newBuilder() 768 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 769 .setDescription("description-1724546052") 770 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 771 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 772 .setDuration(Duration.newBuilder().build()) 773 .setCreateTime(Timestamp.newBuilder().build()) 774 .setUpdateTime(Timestamp.newBuilder().build()) 775 .setLastExecuteTime(Timestamp.newBuilder().build()) 776 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 777 .build(); 778 mockService.addResponse(expectedResponse); 779 780 String name = "projects/project-2608/patchDeployments/patchDeployment-2608"; 781 782 PatchDeployments.PatchDeployment actualResponse = client.pausePatchDeployment(name); 783 Assert.assertEquals(expectedResponse, actualResponse); 784 785 List<String> actualRequests = mockService.getRequestPaths(); 786 Assert.assertEquals(1, actualRequests.size()); 787 788 String apiClientHeaderKey = 789 mockService 790 .getRequestHeaders() 791 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 792 .iterator() 793 .next(); 794 Assert.assertTrue( 795 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 796 .matcher(apiClientHeaderKey) 797 .matches()); 798 } 799 800 @Test pausePatchDeploymentExceptionTest2()801 public void pausePatchDeploymentExceptionTest2() throws Exception { 802 ApiException exception = 803 ApiExceptionFactory.createException( 804 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 805 mockService.addException(exception); 806 807 try { 808 String name = "projects/project-2608/patchDeployments/patchDeployment-2608"; 809 client.pausePatchDeployment(name); 810 Assert.fail("No exception raised"); 811 } catch (InvalidArgumentException e) { 812 // Expected exception. 813 } 814 } 815 816 @Test resumePatchDeploymentTest()817 public void resumePatchDeploymentTest() throws Exception { 818 PatchDeployments.PatchDeployment expectedResponse = 819 PatchDeployments.PatchDeployment.newBuilder() 820 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 821 .setDescription("description-1724546052") 822 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 823 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 824 .setDuration(Duration.newBuilder().build()) 825 .setCreateTime(Timestamp.newBuilder().build()) 826 .setUpdateTime(Timestamp.newBuilder().build()) 827 .setLastExecuteTime(Timestamp.newBuilder().build()) 828 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 829 .build(); 830 mockService.addResponse(expectedResponse); 831 832 PatchDeploymentName name = PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]"); 833 834 PatchDeployments.PatchDeployment actualResponse = client.resumePatchDeployment(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 resumePatchDeploymentExceptionTest()853 public void resumePatchDeploymentExceptionTest() 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 PatchDeploymentName name = PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]"); 861 client.resumePatchDeployment(name); 862 Assert.fail("No exception raised"); 863 } catch (InvalidArgumentException e) { 864 // Expected exception. 865 } 866 } 867 868 @Test resumePatchDeploymentTest2()869 public void resumePatchDeploymentTest2() throws Exception { 870 PatchDeployments.PatchDeployment expectedResponse = 871 PatchDeployments.PatchDeployment.newBuilder() 872 .setName(PatchDeploymentName.of("[PROJECT]", "[PATCH_DEPLOYMENT]").toString()) 873 .setDescription("description-1724546052") 874 .setInstanceFilter(PatchJobs.PatchInstanceFilter.newBuilder().build()) 875 .setPatchConfig(PatchJobs.PatchConfig.newBuilder().build()) 876 .setDuration(Duration.newBuilder().build()) 877 .setCreateTime(Timestamp.newBuilder().build()) 878 .setUpdateTime(Timestamp.newBuilder().build()) 879 .setLastExecuteTime(Timestamp.newBuilder().build()) 880 .setRollout(PatchJobs.PatchRollout.newBuilder().build()) 881 .build(); 882 mockService.addResponse(expectedResponse); 883 884 String name = "projects/project-2608/patchDeployments/patchDeployment-2608"; 885 886 PatchDeployments.PatchDeployment actualResponse = client.resumePatchDeployment(name); 887 Assert.assertEquals(expectedResponse, actualResponse); 888 889 List<String> actualRequests = mockService.getRequestPaths(); 890 Assert.assertEquals(1, actualRequests.size()); 891 892 String apiClientHeaderKey = 893 mockService 894 .getRequestHeaders() 895 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 896 .iterator() 897 .next(); 898 Assert.assertTrue( 899 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 900 .matcher(apiClientHeaderKey) 901 .matches()); 902 } 903 904 @Test resumePatchDeploymentExceptionTest2()905 public void resumePatchDeploymentExceptionTest2() throws Exception { 906 ApiException exception = 907 ApiExceptionFactory.createException( 908 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 909 mockService.addException(exception); 910 911 try { 912 String name = "projects/project-2608/patchDeployments/patchDeployment-2608"; 913 client.resumePatchDeployment(name); 914 Assert.fail("No exception raised"); 915 } catch (InvalidArgumentException e) { 916 // Expected exception. 917 } 918 } 919 920 @Test createGuestPolicyTest()921 public void createGuestPolicyTest() throws Exception { 922 GuestPolicies.GuestPolicy expectedResponse = 923 GuestPolicies.GuestPolicy.newBuilder() 924 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 925 .setDescription("description-1724546052") 926 .setCreateTime(Timestamp.newBuilder().build()) 927 .setUpdateTime(Timestamp.newBuilder().build()) 928 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 929 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 930 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 931 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 932 .setEtag("etag3123477") 933 .build(); 934 mockService.addResponse(expectedResponse); 935 936 ProjectName parent = ProjectName.of("[PROJECT]"); 937 GuestPolicies.GuestPolicy guestPolicy = GuestPolicies.GuestPolicy.newBuilder().build(); 938 939 GuestPolicies.GuestPolicy actualResponse = client.createGuestPolicy(parent, guestPolicy); 940 Assert.assertEquals(expectedResponse, actualResponse); 941 942 List<String> actualRequests = mockService.getRequestPaths(); 943 Assert.assertEquals(1, actualRequests.size()); 944 945 String apiClientHeaderKey = 946 mockService 947 .getRequestHeaders() 948 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 949 .iterator() 950 .next(); 951 Assert.assertTrue( 952 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 953 .matcher(apiClientHeaderKey) 954 .matches()); 955 } 956 957 @Test createGuestPolicyExceptionTest()958 public void createGuestPolicyExceptionTest() throws Exception { 959 ApiException exception = 960 ApiExceptionFactory.createException( 961 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 962 mockService.addException(exception); 963 964 try { 965 ProjectName parent = ProjectName.of("[PROJECT]"); 966 GuestPolicies.GuestPolicy guestPolicy = GuestPolicies.GuestPolicy.newBuilder().build(); 967 client.createGuestPolicy(parent, guestPolicy); 968 Assert.fail("No exception raised"); 969 } catch (InvalidArgumentException e) { 970 // Expected exception. 971 } 972 } 973 974 @Test createGuestPolicyTest2()975 public void createGuestPolicyTest2() throws Exception { 976 GuestPolicies.GuestPolicy expectedResponse = 977 GuestPolicies.GuestPolicy.newBuilder() 978 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 979 .setDescription("description-1724546052") 980 .setCreateTime(Timestamp.newBuilder().build()) 981 .setUpdateTime(Timestamp.newBuilder().build()) 982 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 983 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 984 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 985 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 986 .setEtag("etag3123477") 987 .build(); 988 mockService.addResponse(expectedResponse); 989 990 String parent = "projects/project-2353"; 991 GuestPolicies.GuestPolicy guestPolicy = GuestPolicies.GuestPolicy.newBuilder().build(); 992 993 GuestPolicies.GuestPolicy actualResponse = client.createGuestPolicy(parent, guestPolicy); 994 Assert.assertEquals(expectedResponse, actualResponse); 995 996 List<String> actualRequests = mockService.getRequestPaths(); 997 Assert.assertEquals(1, actualRequests.size()); 998 999 String apiClientHeaderKey = 1000 mockService 1001 .getRequestHeaders() 1002 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1003 .iterator() 1004 .next(); 1005 Assert.assertTrue( 1006 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1007 .matcher(apiClientHeaderKey) 1008 .matches()); 1009 } 1010 1011 @Test createGuestPolicyExceptionTest2()1012 public void createGuestPolicyExceptionTest2() throws Exception { 1013 ApiException exception = 1014 ApiExceptionFactory.createException( 1015 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1016 mockService.addException(exception); 1017 1018 try { 1019 String parent = "projects/project-2353"; 1020 GuestPolicies.GuestPolicy guestPolicy = GuestPolicies.GuestPolicy.newBuilder().build(); 1021 client.createGuestPolicy(parent, guestPolicy); 1022 Assert.fail("No exception raised"); 1023 } catch (InvalidArgumentException e) { 1024 // Expected exception. 1025 } 1026 } 1027 1028 @Test getGuestPolicyTest()1029 public void getGuestPolicyTest() throws Exception { 1030 GuestPolicies.GuestPolicy expectedResponse = 1031 GuestPolicies.GuestPolicy.newBuilder() 1032 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 1033 .setDescription("description-1724546052") 1034 .setCreateTime(Timestamp.newBuilder().build()) 1035 .setUpdateTime(Timestamp.newBuilder().build()) 1036 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 1037 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 1038 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 1039 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 1040 .setEtag("etag3123477") 1041 .build(); 1042 mockService.addResponse(expectedResponse); 1043 1044 GuestPolicyName name = GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]"); 1045 1046 GuestPolicies.GuestPolicy actualResponse = client.getGuestPolicy(name); 1047 Assert.assertEquals(expectedResponse, actualResponse); 1048 1049 List<String> actualRequests = mockService.getRequestPaths(); 1050 Assert.assertEquals(1, actualRequests.size()); 1051 1052 String apiClientHeaderKey = 1053 mockService 1054 .getRequestHeaders() 1055 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1056 .iterator() 1057 .next(); 1058 Assert.assertTrue( 1059 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1060 .matcher(apiClientHeaderKey) 1061 .matches()); 1062 } 1063 1064 @Test getGuestPolicyExceptionTest()1065 public void getGuestPolicyExceptionTest() throws Exception { 1066 ApiException exception = 1067 ApiExceptionFactory.createException( 1068 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1069 mockService.addException(exception); 1070 1071 try { 1072 GuestPolicyName name = GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]"); 1073 client.getGuestPolicy(name); 1074 Assert.fail("No exception raised"); 1075 } catch (InvalidArgumentException e) { 1076 // Expected exception. 1077 } 1078 } 1079 1080 @Test getGuestPolicyTest2()1081 public void getGuestPolicyTest2() throws Exception { 1082 GuestPolicies.GuestPolicy expectedResponse = 1083 GuestPolicies.GuestPolicy.newBuilder() 1084 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 1085 .setDescription("description-1724546052") 1086 .setCreateTime(Timestamp.newBuilder().build()) 1087 .setUpdateTime(Timestamp.newBuilder().build()) 1088 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 1089 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 1090 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 1091 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 1092 .setEtag("etag3123477") 1093 .build(); 1094 mockService.addResponse(expectedResponse); 1095 1096 String name = "projects/project-6612/guestPolicies/guestPolicie-6612"; 1097 1098 GuestPolicies.GuestPolicy actualResponse = client.getGuestPolicy(name); 1099 Assert.assertEquals(expectedResponse, actualResponse); 1100 1101 List<String> actualRequests = mockService.getRequestPaths(); 1102 Assert.assertEquals(1, actualRequests.size()); 1103 1104 String apiClientHeaderKey = 1105 mockService 1106 .getRequestHeaders() 1107 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1108 .iterator() 1109 .next(); 1110 Assert.assertTrue( 1111 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1112 .matcher(apiClientHeaderKey) 1113 .matches()); 1114 } 1115 1116 @Test getGuestPolicyExceptionTest2()1117 public void getGuestPolicyExceptionTest2() throws Exception { 1118 ApiException exception = 1119 ApiExceptionFactory.createException( 1120 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1121 mockService.addException(exception); 1122 1123 try { 1124 String name = "projects/project-6612/guestPolicies/guestPolicie-6612"; 1125 client.getGuestPolicy(name); 1126 Assert.fail("No exception raised"); 1127 } catch (InvalidArgumentException e) { 1128 // Expected exception. 1129 } 1130 } 1131 1132 @Test listGuestPoliciesTest()1133 public void listGuestPoliciesTest() throws Exception { 1134 GuestPolicies.GuestPolicy responsesElement = GuestPolicies.GuestPolicy.newBuilder().build(); 1135 GuestPolicies.ListGuestPoliciesResponse expectedResponse = 1136 GuestPolicies.ListGuestPoliciesResponse.newBuilder() 1137 .setNextPageToken("") 1138 .addAllGuestPolicies(Arrays.asList(responsesElement)) 1139 .build(); 1140 mockService.addResponse(expectedResponse); 1141 1142 ProjectName parent = ProjectName.of("[PROJECT]"); 1143 1144 ListGuestPoliciesPagedResponse pagedListResponse = client.listGuestPolicies(parent); 1145 1146 List<GuestPolicies.GuestPolicy> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1147 1148 Assert.assertEquals(1, resources.size()); 1149 Assert.assertEquals(expectedResponse.getGuestPoliciesList().get(0), resources.get(0)); 1150 1151 List<String> actualRequests = mockService.getRequestPaths(); 1152 Assert.assertEquals(1, actualRequests.size()); 1153 1154 String apiClientHeaderKey = 1155 mockService 1156 .getRequestHeaders() 1157 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1158 .iterator() 1159 .next(); 1160 Assert.assertTrue( 1161 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1162 .matcher(apiClientHeaderKey) 1163 .matches()); 1164 } 1165 1166 @Test listGuestPoliciesExceptionTest()1167 public void listGuestPoliciesExceptionTest() throws Exception { 1168 ApiException exception = 1169 ApiExceptionFactory.createException( 1170 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1171 mockService.addException(exception); 1172 1173 try { 1174 ProjectName parent = ProjectName.of("[PROJECT]"); 1175 client.listGuestPolicies(parent); 1176 Assert.fail("No exception raised"); 1177 } catch (InvalidArgumentException e) { 1178 // Expected exception. 1179 } 1180 } 1181 1182 @Test listGuestPoliciesTest2()1183 public void listGuestPoliciesTest2() throws Exception { 1184 GuestPolicies.GuestPolicy responsesElement = GuestPolicies.GuestPolicy.newBuilder().build(); 1185 GuestPolicies.ListGuestPoliciesResponse expectedResponse = 1186 GuestPolicies.ListGuestPoliciesResponse.newBuilder() 1187 .setNextPageToken("") 1188 .addAllGuestPolicies(Arrays.asList(responsesElement)) 1189 .build(); 1190 mockService.addResponse(expectedResponse); 1191 1192 String parent = "projects/project-2353"; 1193 1194 ListGuestPoliciesPagedResponse pagedListResponse = client.listGuestPolicies(parent); 1195 1196 List<GuestPolicies.GuestPolicy> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1197 1198 Assert.assertEquals(1, resources.size()); 1199 Assert.assertEquals(expectedResponse.getGuestPoliciesList().get(0), resources.get(0)); 1200 1201 List<String> actualRequests = mockService.getRequestPaths(); 1202 Assert.assertEquals(1, actualRequests.size()); 1203 1204 String apiClientHeaderKey = 1205 mockService 1206 .getRequestHeaders() 1207 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1208 .iterator() 1209 .next(); 1210 Assert.assertTrue( 1211 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1212 .matcher(apiClientHeaderKey) 1213 .matches()); 1214 } 1215 1216 @Test listGuestPoliciesExceptionTest2()1217 public void listGuestPoliciesExceptionTest2() throws Exception { 1218 ApiException exception = 1219 ApiExceptionFactory.createException( 1220 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1221 mockService.addException(exception); 1222 1223 try { 1224 String parent = "projects/project-2353"; 1225 client.listGuestPolicies(parent); 1226 Assert.fail("No exception raised"); 1227 } catch (InvalidArgumentException e) { 1228 // Expected exception. 1229 } 1230 } 1231 1232 @Test updateGuestPolicyTest()1233 public void updateGuestPolicyTest() throws Exception { 1234 GuestPolicies.GuestPolicy expectedResponse = 1235 GuestPolicies.GuestPolicy.newBuilder() 1236 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 1237 .setDescription("description-1724546052") 1238 .setCreateTime(Timestamp.newBuilder().build()) 1239 .setUpdateTime(Timestamp.newBuilder().build()) 1240 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 1241 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 1242 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 1243 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 1244 .setEtag("etag3123477") 1245 .build(); 1246 mockService.addResponse(expectedResponse); 1247 1248 GuestPolicies.GuestPolicy guestPolicy = 1249 GuestPolicies.GuestPolicy.newBuilder() 1250 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 1251 .setDescription("description-1724546052") 1252 .setCreateTime(Timestamp.newBuilder().build()) 1253 .setUpdateTime(Timestamp.newBuilder().build()) 1254 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 1255 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 1256 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 1257 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 1258 .setEtag("etag3123477") 1259 .build(); 1260 FieldMask updateMask = FieldMask.newBuilder().build(); 1261 1262 GuestPolicies.GuestPolicy actualResponse = client.updateGuestPolicy(guestPolicy, updateMask); 1263 Assert.assertEquals(expectedResponse, actualResponse); 1264 1265 List<String> actualRequests = mockService.getRequestPaths(); 1266 Assert.assertEquals(1, actualRequests.size()); 1267 1268 String apiClientHeaderKey = 1269 mockService 1270 .getRequestHeaders() 1271 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1272 .iterator() 1273 .next(); 1274 Assert.assertTrue( 1275 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1276 .matcher(apiClientHeaderKey) 1277 .matches()); 1278 } 1279 1280 @Test updateGuestPolicyExceptionTest()1281 public void updateGuestPolicyExceptionTest() throws Exception { 1282 ApiException exception = 1283 ApiExceptionFactory.createException( 1284 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1285 mockService.addException(exception); 1286 1287 try { 1288 GuestPolicies.GuestPolicy guestPolicy = 1289 GuestPolicies.GuestPolicy.newBuilder() 1290 .setName(GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]").toString()) 1291 .setDescription("description-1724546052") 1292 .setCreateTime(Timestamp.newBuilder().build()) 1293 .setUpdateTime(Timestamp.newBuilder().build()) 1294 .setAssignment(GuestPolicies.Assignment.newBuilder().build()) 1295 .addAllPackages(new ArrayList<GuestPolicies.Package>()) 1296 .addAllPackageRepositories(new ArrayList<GuestPolicies.PackageRepository>()) 1297 .addAllRecipes(new ArrayList<GuestPolicies.SoftwareRecipe>()) 1298 .setEtag("etag3123477") 1299 .build(); 1300 FieldMask updateMask = FieldMask.newBuilder().build(); 1301 client.updateGuestPolicy(guestPolicy, updateMask); 1302 Assert.fail("No exception raised"); 1303 } catch (InvalidArgumentException e) { 1304 // Expected exception. 1305 } 1306 } 1307 1308 @Test deleteGuestPolicyTest()1309 public void deleteGuestPolicyTest() throws Exception { 1310 Empty expectedResponse = Empty.newBuilder().build(); 1311 mockService.addResponse(expectedResponse); 1312 1313 GuestPolicyName name = GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]"); 1314 1315 client.deleteGuestPolicy(name); 1316 1317 List<String> actualRequests = mockService.getRequestPaths(); 1318 Assert.assertEquals(1, actualRequests.size()); 1319 1320 String apiClientHeaderKey = 1321 mockService 1322 .getRequestHeaders() 1323 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1324 .iterator() 1325 .next(); 1326 Assert.assertTrue( 1327 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1328 .matcher(apiClientHeaderKey) 1329 .matches()); 1330 } 1331 1332 @Test deleteGuestPolicyExceptionTest()1333 public void deleteGuestPolicyExceptionTest() throws Exception { 1334 ApiException exception = 1335 ApiExceptionFactory.createException( 1336 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1337 mockService.addException(exception); 1338 1339 try { 1340 GuestPolicyName name = GuestPolicyName.of("[PROJECT]", "[GUEST_POLICY]"); 1341 client.deleteGuestPolicy(name); 1342 Assert.fail("No exception raised"); 1343 } catch (InvalidArgumentException e) { 1344 // Expected exception. 1345 } 1346 } 1347 1348 @Test deleteGuestPolicyTest2()1349 public void deleteGuestPolicyTest2() throws Exception { 1350 Empty expectedResponse = Empty.newBuilder().build(); 1351 mockService.addResponse(expectedResponse); 1352 1353 String name = "projects/project-6612/guestPolicies/guestPolicie-6612"; 1354 1355 client.deleteGuestPolicy(name); 1356 1357 List<String> actualRequests = mockService.getRequestPaths(); 1358 Assert.assertEquals(1, actualRequests.size()); 1359 1360 String apiClientHeaderKey = 1361 mockService 1362 .getRequestHeaders() 1363 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1364 .iterator() 1365 .next(); 1366 Assert.assertTrue( 1367 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1368 .matcher(apiClientHeaderKey) 1369 .matches()); 1370 } 1371 1372 @Test deleteGuestPolicyExceptionTest2()1373 public void deleteGuestPolicyExceptionTest2() throws Exception { 1374 ApiException exception = 1375 ApiExceptionFactory.createException( 1376 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1377 mockService.addException(exception); 1378 1379 try { 1380 String name = "projects/project-6612/guestPolicies/guestPolicie-6612"; 1381 client.deleteGuestPolicy(name); 1382 Assert.fail("No exception raised"); 1383 } catch (InvalidArgumentException e) { 1384 // Expected exception. 1385 } 1386 } 1387 1388 @Test lookupEffectiveGuestPolicyTest()1389 public void lookupEffectiveGuestPolicyTest() throws Exception { 1390 GuestPolicies.EffectiveGuestPolicy expectedResponse = 1391 GuestPolicies.EffectiveGuestPolicy.newBuilder() 1392 .addAllPackages(new ArrayList<GuestPolicies.EffectiveGuestPolicy.SourcedPackage>()) 1393 .addAllPackageRepositories( 1394 new ArrayList<GuestPolicies.EffectiveGuestPolicy.SourcedPackageRepository>()) 1395 .addAllSoftwareRecipes( 1396 new ArrayList<GuestPolicies.EffectiveGuestPolicy.SourcedSoftwareRecipe>()) 1397 .build(); 1398 mockService.addResponse(expectedResponse); 1399 1400 GuestPolicies.LookupEffectiveGuestPolicyRequest request = 1401 GuestPolicies.LookupEffectiveGuestPolicyRequest.newBuilder() 1402 .setInstance("projects/project-4489/zones/zone-4489/instances/instance-4489") 1403 .setOsShortName("osShortName1253394339") 1404 .setOsVersion("osVersion1812004436") 1405 .setOsArchitecture("osArchitecture1339954519") 1406 .build(); 1407 1408 GuestPolicies.EffectiveGuestPolicy actualResponse = client.lookupEffectiveGuestPolicy(request); 1409 Assert.assertEquals(expectedResponse, actualResponse); 1410 1411 List<String> actualRequests = mockService.getRequestPaths(); 1412 Assert.assertEquals(1, actualRequests.size()); 1413 1414 String apiClientHeaderKey = 1415 mockService 1416 .getRequestHeaders() 1417 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1418 .iterator() 1419 .next(); 1420 Assert.assertTrue( 1421 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1422 .matcher(apiClientHeaderKey) 1423 .matches()); 1424 } 1425 1426 @Test lookupEffectiveGuestPolicyExceptionTest()1427 public void lookupEffectiveGuestPolicyExceptionTest() throws Exception { 1428 ApiException exception = 1429 ApiExceptionFactory.createException( 1430 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1431 mockService.addException(exception); 1432 1433 try { 1434 GuestPolicies.LookupEffectiveGuestPolicyRequest request = 1435 GuestPolicies.LookupEffectiveGuestPolicyRequest.newBuilder() 1436 .setInstance("projects/project-4489/zones/zone-4489/instances/instance-4489") 1437 .setOsShortName("osShortName1253394339") 1438 .setOsVersion("osVersion1812004436") 1439 .setOsArchitecture("osArchitecture1339954519") 1440 .build(); 1441 client.lookupEffectiveGuestPolicy(request); 1442 Assert.fail("No exception raised"); 1443 } catch (InvalidArgumentException e) { 1444 // Expected exception. 1445 } 1446 } 1447 } 1448