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.bigquery.migration.v2alpha; 18 19 import static com.google.cloud.bigquery.migration.v2alpha.MigrationServiceClient.ListMigrationSubtasksPagedResponse; 20 import static com.google.cloud.bigquery.migration.v2alpha.MigrationServiceClient.ListMigrationWorkflowsPagedResponse; 21 22 import com.google.api.gax.core.NoCredentialsProvider; 23 import com.google.api.gax.grpc.GaxGrpcProperties; 24 import com.google.api.gax.grpc.testing.LocalChannelProvider; 25 import com.google.api.gax.grpc.testing.MockGrpcService; 26 import com.google.api.gax.grpc.testing.MockServiceHelper; 27 import com.google.api.gax.rpc.ApiClientHeaderProvider; 28 import com.google.api.gax.rpc.InvalidArgumentException; 29 import com.google.common.collect.Lists; 30 import com.google.protobuf.AbstractMessage; 31 import com.google.protobuf.Empty; 32 import com.google.protobuf.Timestamp; 33 import com.google.rpc.ErrorInfo; 34 import io.grpc.StatusRuntimeException; 35 import java.io.IOException; 36 import java.util.ArrayList; 37 import java.util.Arrays; 38 import java.util.HashMap; 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 MigrationServiceClientTest { 51 private static MockMigrationService mockMigrationService; 52 private static MockServiceHelper mockServiceHelper; 53 private LocalChannelProvider channelProvider; 54 private MigrationServiceClient client; 55 56 @BeforeClass startStaticServer()57 public static void startStaticServer() { 58 mockMigrationService = new MockMigrationService(); 59 mockServiceHelper = 60 new MockServiceHelper( 61 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockMigrationService)); 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 MigrationServiceSettings settings = 75 MigrationServiceSettings.newBuilder() 76 .setTransportChannelProvider(channelProvider) 77 .setCredentialsProvider(NoCredentialsProvider.create()) 78 .build(); 79 client = MigrationServiceClient.create(settings); 80 } 81 82 @After tearDown()83 public void tearDown() throws Exception { 84 client.close(); 85 } 86 87 @Test createMigrationWorkflowTest()88 public void createMigrationWorkflowTest() throws Exception { 89 MigrationWorkflow expectedResponse = 90 MigrationWorkflow.newBuilder() 91 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 92 .setDisplayName("displayName1714148973") 93 .putAllTasks(new HashMap<String, MigrationTask>()) 94 .setCreateTime(Timestamp.newBuilder().build()) 95 .setLastUpdateTime(Timestamp.newBuilder().build()) 96 .build(); 97 mockMigrationService.addResponse(expectedResponse); 98 99 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 100 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 101 102 MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); 103 Assert.assertEquals(expectedResponse, actualResponse); 104 105 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 106 Assert.assertEquals(1, actualRequests.size()); 107 CreateMigrationWorkflowRequest actualRequest = 108 ((CreateMigrationWorkflowRequest) actualRequests.get(0)); 109 110 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 111 Assert.assertEquals(migrationWorkflow, actualRequest.getMigrationWorkflow()); 112 Assert.assertTrue( 113 channelProvider.isHeaderSent( 114 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 115 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 116 } 117 118 @Test createMigrationWorkflowExceptionTest()119 public void createMigrationWorkflowExceptionTest() throws Exception { 120 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 121 mockMigrationService.addException(exception); 122 123 try { 124 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 125 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 126 client.createMigrationWorkflow(parent, migrationWorkflow); 127 Assert.fail("No exception raised"); 128 } catch (InvalidArgumentException e) { 129 // Expected exception. 130 } 131 } 132 133 @Test createMigrationWorkflowTest2()134 public void createMigrationWorkflowTest2() throws Exception { 135 MigrationWorkflow expectedResponse = 136 MigrationWorkflow.newBuilder() 137 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 138 .setDisplayName("displayName1714148973") 139 .putAllTasks(new HashMap<String, MigrationTask>()) 140 .setCreateTime(Timestamp.newBuilder().build()) 141 .setLastUpdateTime(Timestamp.newBuilder().build()) 142 .build(); 143 mockMigrationService.addResponse(expectedResponse); 144 145 String parent = "parent-995424086"; 146 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 147 148 MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); 149 Assert.assertEquals(expectedResponse, actualResponse); 150 151 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 152 Assert.assertEquals(1, actualRequests.size()); 153 CreateMigrationWorkflowRequest actualRequest = 154 ((CreateMigrationWorkflowRequest) actualRequests.get(0)); 155 156 Assert.assertEquals(parent, actualRequest.getParent()); 157 Assert.assertEquals(migrationWorkflow, actualRequest.getMigrationWorkflow()); 158 Assert.assertTrue( 159 channelProvider.isHeaderSent( 160 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 161 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 162 } 163 164 @Test createMigrationWorkflowExceptionTest2()165 public void createMigrationWorkflowExceptionTest2() throws Exception { 166 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 167 mockMigrationService.addException(exception); 168 169 try { 170 String parent = "parent-995424086"; 171 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 172 client.createMigrationWorkflow(parent, migrationWorkflow); 173 Assert.fail("No exception raised"); 174 } catch (InvalidArgumentException e) { 175 // Expected exception. 176 } 177 } 178 179 @Test getMigrationWorkflowTest()180 public void getMigrationWorkflowTest() throws Exception { 181 MigrationWorkflow expectedResponse = 182 MigrationWorkflow.newBuilder() 183 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 184 .setDisplayName("displayName1714148973") 185 .putAllTasks(new HashMap<String, MigrationTask>()) 186 .setCreateTime(Timestamp.newBuilder().build()) 187 .setLastUpdateTime(Timestamp.newBuilder().build()) 188 .build(); 189 mockMigrationService.addResponse(expectedResponse); 190 191 MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 192 193 MigrationWorkflow actualResponse = client.getMigrationWorkflow(name); 194 Assert.assertEquals(expectedResponse, actualResponse); 195 196 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 197 Assert.assertEquals(1, actualRequests.size()); 198 GetMigrationWorkflowRequest actualRequest = 199 ((GetMigrationWorkflowRequest) 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 getMigrationWorkflowExceptionTest()209 public void getMigrationWorkflowExceptionTest() throws Exception { 210 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 211 mockMigrationService.addException(exception); 212 213 try { 214 MigrationWorkflowName name = 215 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 216 client.getMigrationWorkflow(name); 217 Assert.fail("No exception raised"); 218 } catch (InvalidArgumentException e) { 219 // Expected exception. 220 } 221 } 222 223 @Test getMigrationWorkflowTest2()224 public void getMigrationWorkflowTest2() throws Exception { 225 MigrationWorkflow expectedResponse = 226 MigrationWorkflow.newBuilder() 227 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 228 .setDisplayName("displayName1714148973") 229 .putAllTasks(new HashMap<String, MigrationTask>()) 230 .setCreateTime(Timestamp.newBuilder().build()) 231 .setLastUpdateTime(Timestamp.newBuilder().build()) 232 .build(); 233 mockMigrationService.addResponse(expectedResponse); 234 235 String name = "name3373707"; 236 237 MigrationWorkflow actualResponse = client.getMigrationWorkflow(name); 238 Assert.assertEquals(expectedResponse, actualResponse); 239 240 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 241 Assert.assertEquals(1, actualRequests.size()); 242 GetMigrationWorkflowRequest actualRequest = 243 ((GetMigrationWorkflowRequest) actualRequests.get(0)); 244 245 Assert.assertEquals(name, actualRequest.getName()); 246 Assert.assertTrue( 247 channelProvider.isHeaderSent( 248 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 249 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 250 } 251 252 @Test getMigrationWorkflowExceptionTest2()253 public void getMigrationWorkflowExceptionTest2() throws Exception { 254 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 255 mockMigrationService.addException(exception); 256 257 try { 258 String name = "name3373707"; 259 client.getMigrationWorkflow(name); 260 Assert.fail("No exception raised"); 261 } catch (InvalidArgumentException e) { 262 // Expected exception. 263 } 264 } 265 266 @Test listMigrationWorkflowsTest()267 public void listMigrationWorkflowsTest() throws Exception { 268 MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); 269 ListMigrationWorkflowsResponse expectedResponse = 270 ListMigrationWorkflowsResponse.newBuilder() 271 .setNextPageToken("") 272 .addAllMigrationWorkflows(Arrays.asList(responsesElement)) 273 .build(); 274 mockMigrationService.addResponse(expectedResponse); 275 276 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 277 278 ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); 279 280 List<MigrationWorkflow> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 281 282 Assert.assertEquals(1, resources.size()); 283 Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().get(0), resources.get(0)); 284 285 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 286 Assert.assertEquals(1, actualRequests.size()); 287 ListMigrationWorkflowsRequest actualRequest = 288 ((ListMigrationWorkflowsRequest) actualRequests.get(0)); 289 290 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 291 Assert.assertTrue( 292 channelProvider.isHeaderSent( 293 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 294 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 295 } 296 297 @Test listMigrationWorkflowsExceptionTest()298 public void listMigrationWorkflowsExceptionTest() throws Exception { 299 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 300 mockMigrationService.addException(exception); 301 302 try { 303 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 304 client.listMigrationWorkflows(parent); 305 Assert.fail("No exception raised"); 306 } catch (InvalidArgumentException e) { 307 // Expected exception. 308 } 309 } 310 311 @Test listMigrationWorkflowsTest2()312 public void listMigrationWorkflowsTest2() throws Exception { 313 MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); 314 ListMigrationWorkflowsResponse expectedResponse = 315 ListMigrationWorkflowsResponse.newBuilder() 316 .setNextPageToken("") 317 .addAllMigrationWorkflows(Arrays.asList(responsesElement)) 318 .build(); 319 mockMigrationService.addResponse(expectedResponse); 320 321 String parent = "parent-995424086"; 322 323 ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); 324 325 List<MigrationWorkflow> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 326 327 Assert.assertEquals(1, resources.size()); 328 Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().get(0), resources.get(0)); 329 330 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 331 Assert.assertEquals(1, actualRequests.size()); 332 ListMigrationWorkflowsRequest actualRequest = 333 ((ListMigrationWorkflowsRequest) actualRequests.get(0)); 334 335 Assert.assertEquals(parent, actualRequest.getParent()); 336 Assert.assertTrue( 337 channelProvider.isHeaderSent( 338 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 339 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 340 } 341 342 @Test listMigrationWorkflowsExceptionTest2()343 public void listMigrationWorkflowsExceptionTest2() throws Exception { 344 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 345 mockMigrationService.addException(exception); 346 347 try { 348 String parent = "parent-995424086"; 349 client.listMigrationWorkflows(parent); 350 Assert.fail("No exception raised"); 351 } catch (InvalidArgumentException e) { 352 // Expected exception. 353 } 354 } 355 356 @Test deleteMigrationWorkflowTest()357 public void deleteMigrationWorkflowTest() throws Exception { 358 Empty expectedResponse = Empty.newBuilder().build(); 359 mockMigrationService.addResponse(expectedResponse); 360 361 MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 362 363 client.deleteMigrationWorkflow(name); 364 365 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 366 Assert.assertEquals(1, actualRequests.size()); 367 DeleteMigrationWorkflowRequest actualRequest = 368 ((DeleteMigrationWorkflowRequest) actualRequests.get(0)); 369 370 Assert.assertEquals(name.toString(), actualRequest.getName()); 371 Assert.assertTrue( 372 channelProvider.isHeaderSent( 373 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 374 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 375 } 376 377 @Test deleteMigrationWorkflowExceptionTest()378 public void deleteMigrationWorkflowExceptionTest() throws Exception { 379 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 380 mockMigrationService.addException(exception); 381 382 try { 383 MigrationWorkflowName name = 384 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 385 client.deleteMigrationWorkflow(name); 386 Assert.fail("No exception raised"); 387 } catch (InvalidArgumentException e) { 388 // Expected exception. 389 } 390 } 391 392 @Test deleteMigrationWorkflowTest2()393 public void deleteMigrationWorkflowTest2() throws Exception { 394 Empty expectedResponse = Empty.newBuilder().build(); 395 mockMigrationService.addResponse(expectedResponse); 396 397 String name = "name3373707"; 398 399 client.deleteMigrationWorkflow(name); 400 401 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 402 Assert.assertEquals(1, actualRequests.size()); 403 DeleteMigrationWorkflowRequest actualRequest = 404 ((DeleteMigrationWorkflowRequest) actualRequests.get(0)); 405 406 Assert.assertEquals(name, actualRequest.getName()); 407 Assert.assertTrue( 408 channelProvider.isHeaderSent( 409 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 410 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 411 } 412 413 @Test deleteMigrationWorkflowExceptionTest2()414 public void deleteMigrationWorkflowExceptionTest2() throws Exception { 415 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 416 mockMigrationService.addException(exception); 417 418 try { 419 String name = "name3373707"; 420 client.deleteMigrationWorkflow(name); 421 Assert.fail("No exception raised"); 422 } catch (InvalidArgumentException e) { 423 // Expected exception. 424 } 425 } 426 427 @Test startMigrationWorkflowTest()428 public void startMigrationWorkflowTest() throws Exception { 429 Empty expectedResponse = Empty.newBuilder().build(); 430 mockMigrationService.addResponse(expectedResponse); 431 432 MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 433 434 client.startMigrationWorkflow(name); 435 436 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 437 Assert.assertEquals(1, actualRequests.size()); 438 StartMigrationWorkflowRequest actualRequest = 439 ((StartMigrationWorkflowRequest) actualRequests.get(0)); 440 441 Assert.assertEquals(name.toString(), actualRequest.getName()); 442 Assert.assertTrue( 443 channelProvider.isHeaderSent( 444 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 445 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 446 } 447 448 @Test startMigrationWorkflowExceptionTest()449 public void startMigrationWorkflowExceptionTest() throws Exception { 450 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 451 mockMigrationService.addException(exception); 452 453 try { 454 MigrationWorkflowName name = 455 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 456 client.startMigrationWorkflow(name); 457 Assert.fail("No exception raised"); 458 } catch (InvalidArgumentException e) { 459 // Expected exception. 460 } 461 } 462 463 @Test startMigrationWorkflowTest2()464 public void startMigrationWorkflowTest2() throws Exception { 465 Empty expectedResponse = Empty.newBuilder().build(); 466 mockMigrationService.addResponse(expectedResponse); 467 468 String name = "name3373707"; 469 470 client.startMigrationWorkflow(name); 471 472 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 473 Assert.assertEquals(1, actualRequests.size()); 474 StartMigrationWorkflowRequest actualRequest = 475 ((StartMigrationWorkflowRequest) actualRequests.get(0)); 476 477 Assert.assertEquals(name, actualRequest.getName()); 478 Assert.assertTrue( 479 channelProvider.isHeaderSent( 480 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 481 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 482 } 483 484 @Test startMigrationWorkflowExceptionTest2()485 public void startMigrationWorkflowExceptionTest2() throws Exception { 486 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 487 mockMigrationService.addException(exception); 488 489 try { 490 String name = "name3373707"; 491 client.startMigrationWorkflow(name); 492 Assert.fail("No exception raised"); 493 } catch (InvalidArgumentException e) { 494 // Expected exception. 495 } 496 } 497 498 @Test getMigrationSubtaskTest()499 public void getMigrationSubtaskTest() throws Exception { 500 MigrationSubtask expectedResponse = 501 MigrationSubtask.newBuilder() 502 .setName( 503 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") 504 .toString()) 505 .setTaskId("taskId-880873088") 506 .setType("type3575610") 507 .setProcessingError(ErrorInfo.newBuilder().build()) 508 .addAllResourceErrorDetails(new ArrayList<ResourceErrorDetail>()) 509 .setResourceErrorCount(-929997465) 510 .setCreateTime(Timestamp.newBuilder().build()) 511 .setLastUpdateTime(Timestamp.newBuilder().build()) 512 .addAllMetrics(new ArrayList<TimeSeries>()) 513 .build(); 514 mockMigrationService.addResponse(expectedResponse); 515 516 MigrationSubtaskName name = 517 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); 518 519 MigrationSubtask actualResponse = client.getMigrationSubtask(name); 520 Assert.assertEquals(expectedResponse, actualResponse); 521 522 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 523 Assert.assertEquals(1, actualRequests.size()); 524 GetMigrationSubtaskRequest actualRequest = ((GetMigrationSubtaskRequest) actualRequests.get(0)); 525 526 Assert.assertEquals(name.toString(), actualRequest.getName()); 527 Assert.assertTrue( 528 channelProvider.isHeaderSent( 529 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 530 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 531 } 532 533 @Test getMigrationSubtaskExceptionTest()534 public void getMigrationSubtaskExceptionTest() throws Exception { 535 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 536 mockMigrationService.addException(exception); 537 538 try { 539 MigrationSubtaskName name = 540 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); 541 client.getMigrationSubtask(name); 542 Assert.fail("No exception raised"); 543 } catch (InvalidArgumentException e) { 544 // Expected exception. 545 } 546 } 547 548 @Test getMigrationSubtaskTest2()549 public void getMigrationSubtaskTest2() throws Exception { 550 MigrationSubtask expectedResponse = 551 MigrationSubtask.newBuilder() 552 .setName( 553 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") 554 .toString()) 555 .setTaskId("taskId-880873088") 556 .setType("type3575610") 557 .setProcessingError(ErrorInfo.newBuilder().build()) 558 .addAllResourceErrorDetails(new ArrayList<ResourceErrorDetail>()) 559 .setResourceErrorCount(-929997465) 560 .setCreateTime(Timestamp.newBuilder().build()) 561 .setLastUpdateTime(Timestamp.newBuilder().build()) 562 .addAllMetrics(new ArrayList<TimeSeries>()) 563 .build(); 564 mockMigrationService.addResponse(expectedResponse); 565 566 String name = "name3373707"; 567 568 MigrationSubtask actualResponse = client.getMigrationSubtask(name); 569 Assert.assertEquals(expectedResponse, actualResponse); 570 571 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 572 Assert.assertEquals(1, actualRequests.size()); 573 GetMigrationSubtaskRequest actualRequest = ((GetMigrationSubtaskRequest) actualRequests.get(0)); 574 575 Assert.assertEquals(name, actualRequest.getName()); 576 Assert.assertTrue( 577 channelProvider.isHeaderSent( 578 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 579 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 580 } 581 582 @Test getMigrationSubtaskExceptionTest2()583 public void getMigrationSubtaskExceptionTest2() throws Exception { 584 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 585 mockMigrationService.addException(exception); 586 587 try { 588 String name = "name3373707"; 589 client.getMigrationSubtask(name); 590 Assert.fail("No exception raised"); 591 } catch (InvalidArgumentException e) { 592 // Expected exception. 593 } 594 } 595 596 @Test listMigrationSubtasksTest()597 public void listMigrationSubtasksTest() throws Exception { 598 MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); 599 ListMigrationSubtasksResponse expectedResponse = 600 ListMigrationSubtasksResponse.newBuilder() 601 .setNextPageToken("") 602 .addAllMigrationSubtasks(Arrays.asList(responsesElement)) 603 .build(); 604 mockMigrationService.addResponse(expectedResponse); 605 606 MigrationWorkflowName parent = 607 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 608 609 ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); 610 611 List<MigrationSubtask> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 612 613 Assert.assertEquals(1, resources.size()); 614 Assert.assertEquals(expectedResponse.getMigrationSubtasksList().get(0), resources.get(0)); 615 616 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 617 Assert.assertEquals(1, actualRequests.size()); 618 ListMigrationSubtasksRequest actualRequest = 619 ((ListMigrationSubtasksRequest) actualRequests.get(0)); 620 621 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 622 Assert.assertTrue( 623 channelProvider.isHeaderSent( 624 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 625 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 626 } 627 628 @Test listMigrationSubtasksExceptionTest()629 public void listMigrationSubtasksExceptionTest() throws Exception { 630 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 631 mockMigrationService.addException(exception); 632 633 try { 634 MigrationWorkflowName parent = 635 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 636 client.listMigrationSubtasks(parent); 637 Assert.fail("No exception raised"); 638 } catch (InvalidArgumentException e) { 639 // Expected exception. 640 } 641 } 642 643 @Test listMigrationSubtasksTest2()644 public void listMigrationSubtasksTest2() throws Exception { 645 MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); 646 ListMigrationSubtasksResponse expectedResponse = 647 ListMigrationSubtasksResponse.newBuilder() 648 .setNextPageToken("") 649 .addAllMigrationSubtasks(Arrays.asList(responsesElement)) 650 .build(); 651 mockMigrationService.addResponse(expectedResponse); 652 653 String parent = "parent-995424086"; 654 655 ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); 656 657 List<MigrationSubtask> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 658 659 Assert.assertEquals(1, resources.size()); 660 Assert.assertEquals(expectedResponse.getMigrationSubtasksList().get(0), resources.get(0)); 661 662 List<AbstractMessage> actualRequests = mockMigrationService.getRequests(); 663 Assert.assertEquals(1, actualRequests.size()); 664 ListMigrationSubtasksRequest actualRequest = 665 ((ListMigrationSubtasksRequest) actualRequests.get(0)); 666 667 Assert.assertEquals(parent, actualRequest.getParent()); 668 Assert.assertTrue( 669 channelProvider.isHeaderSent( 670 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 671 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 672 } 673 674 @Test listMigrationSubtasksExceptionTest2()675 public void listMigrationSubtasksExceptionTest2() throws Exception { 676 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 677 mockMigrationService.addException(exception); 678 679 try { 680 String parent = "parent-995424086"; 681 client.listMigrationSubtasks(parent); 682 Assert.fail("No exception raised"); 683 } catch (InvalidArgumentException e) { 684 // Expected exception. 685 } 686 } 687 } 688