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