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