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.httpjson.GaxHttpJsonProperties; 24 import com.google.api.gax.httpjson.testing.MockHttpService; 25 import com.google.api.gax.rpc.ApiClientHeaderProvider; 26 import com.google.api.gax.rpc.ApiException; 27 import com.google.api.gax.rpc.ApiExceptionFactory; 28 import com.google.api.gax.rpc.InvalidArgumentException; 29 import com.google.api.gax.rpc.StatusCode; 30 import com.google.api.gax.rpc.testing.FakeStatusCode; 31 import com.google.cloud.bigquery.migration.v2alpha.stub.HttpJsonMigrationServiceStub; 32 import com.google.common.collect.Lists; 33 import com.google.protobuf.Empty; 34 import com.google.protobuf.Timestamp; 35 import com.google.rpc.ErrorInfo; 36 import java.io.IOException; 37 import java.util.ArrayList; 38 import java.util.Arrays; 39 import java.util.HashMap; 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 MigrationServiceClientHttpJsonTest { 51 private static MockHttpService mockService; 52 private static MigrationServiceClient client; 53 54 @BeforeClass startStaticServer()55 public static void startStaticServer() throws IOException { 56 mockService = 57 new MockHttpService( 58 HttpJsonMigrationServiceStub.getMethodDescriptors(), 59 MigrationServiceSettings.getDefaultEndpoint()); 60 MigrationServiceSettings settings = 61 MigrationServiceSettings.newHttpJsonBuilder() 62 .setTransportChannelProvider( 63 MigrationServiceSettings.defaultHttpJsonTransportProviderBuilder() 64 .setHttpTransport(mockService) 65 .build()) 66 .setCredentialsProvider(NoCredentialsProvider.create()) 67 .build(); 68 client = MigrationServiceClient.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 createMigrationWorkflowTest()85 public void createMigrationWorkflowTest() throws Exception { 86 MigrationWorkflow expectedResponse = 87 MigrationWorkflow.newBuilder() 88 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 89 .setDisplayName("displayName1714148973") 90 .putAllTasks(new HashMap<String, MigrationTask>()) 91 .setCreateTime(Timestamp.newBuilder().build()) 92 .setLastUpdateTime(Timestamp.newBuilder().build()) 93 .build(); 94 mockService.addResponse(expectedResponse); 95 96 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 97 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 98 99 MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); 100 Assert.assertEquals(expectedResponse, actualResponse); 101 102 List<String> actualRequests = mockService.getRequestPaths(); 103 Assert.assertEquals(1, actualRequests.size()); 104 105 String apiClientHeaderKey = 106 mockService 107 .getRequestHeaders() 108 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 109 .iterator() 110 .next(); 111 Assert.assertTrue( 112 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 113 .matcher(apiClientHeaderKey) 114 .matches()); 115 } 116 117 @Test createMigrationWorkflowExceptionTest()118 public void createMigrationWorkflowExceptionTest() throws Exception { 119 ApiException exception = 120 ApiExceptionFactory.createException( 121 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 122 mockService.addException(exception); 123 124 try { 125 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 126 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 127 client.createMigrationWorkflow(parent, migrationWorkflow); 128 Assert.fail("No exception raised"); 129 } catch (InvalidArgumentException e) { 130 // Expected exception. 131 } 132 } 133 134 @Test createMigrationWorkflowTest2()135 public void createMigrationWorkflowTest2() throws Exception { 136 MigrationWorkflow expectedResponse = 137 MigrationWorkflow.newBuilder() 138 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 139 .setDisplayName("displayName1714148973") 140 .putAllTasks(new HashMap<String, MigrationTask>()) 141 .setCreateTime(Timestamp.newBuilder().build()) 142 .setLastUpdateTime(Timestamp.newBuilder().build()) 143 .build(); 144 mockService.addResponse(expectedResponse); 145 146 String parent = "projects/project-5833/locations/location-5833"; 147 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 148 149 MigrationWorkflow actualResponse = client.createMigrationWorkflow(parent, migrationWorkflow); 150 Assert.assertEquals(expectedResponse, actualResponse); 151 152 List<String> actualRequests = mockService.getRequestPaths(); 153 Assert.assertEquals(1, actualRequests.size()); 154 155 String apiClientHeaderKey = 156 mockService 157 .getRequestHeaders() 158 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 159 .iterator() 160 .next(); 161 Assert.assertTrue( 162 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 163 .matcher(apiClientHeaderKey) 164 .matches()); 165 } 166 167 @Test createMigrationWorkflowExceptionTest2()168 public void createMigrationWorkflowExceptionTest2() throws Exception { 169 ApiException exception = 170 ApiExceptionFactory.createException( 171 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 172 mockService.addException(exception); 173 174 try { 175 String parent = "projects/project-5833/locations/location-5833"; 176 MigrationWorkflow migrationWorkflow = MigrationWorkflow.newBuilder().build(); 177 client.createMigrationWorkflow(parent, migrationWorkflow); 178 Assert.fail("No exception raised"); 179 } catch (InvalidArgumentException e) { 180 // Expected exception. 181 } 182 } 183 184 @Test getMigrationWorkflowTest()185 public void getMigrationWorkflowTest() throws Exception { 186 MigrationWorkflow expectedResponse = 187 MigrationWorkflow.newBuilder() 188 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 189 .setDisplayName("displayName1714148973") 190 .putAllTasks(new HashMap<String, MigrationTask>()) 191 .setCreateTime(Timestamp.newBuilder().build()) 192 .setLastUpdateTime(Timestamp.newBuilder().build()) 193 .build(); 194 mockService.addResponse(expectedResponse); 195 196 MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 197 198 MigrationWorkflow actualResponse = client.getMigrationWorkflow(name); 199 Assert.assertEquals(expectedResponse, actualResponse); 200 201 List<String> actualRequests = mockService.getRequestPaths(); 202 Assert.assertEquals(1, actualRequests.size()); 203 204 String apiClientHeaderKey = 205 mockService 206 .getRequestHeaders() 207 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 208 .iterator() 209 .next(); 210 Assert.assertTrue( 211 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 212 .matcher(apiClientHeaderKey) 213 .matches()); 214 } 215 216 @Test getMigrationWorkflowExceptionTest()217 public void getMigrationWorkflowExceptionTest() throws Exception { 218 ApiException exception = 219 ApiExceptionFactory.createException( 220 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 221 mockService.addException(exception); 222 223 try { 224 MigrationWorkflowName name = 225 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 226 client.getMigrationWorkflow(name); 227 Assert.fail("No exception raised"); 228 } catch (InvalidArgumentException e) { 229 // Expected exception. 230 } 231 } 232 233 @Test getMigrationWorkflowTest2()234 public void getMigrationWorkflowTest2() throws Exception { 235 MigrationWorkflow expectedResponse = 236 MigrationWorkflow.newBuilder() 237 .setName(MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]").toString()) 238 .setDisplayName("displayName1714148973") 239 .putAllTasks(new HashMap<String, MigrationTask>()) 240 .setCreateTime(Timestamp.newBuilder().build()) 241 .setLastUpdateTime(Timestamp.newBuilder().build()) 242 .build(); 243 mockService.addResponse(expectedResponse); 244 245 String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; 246 247 MigrationWorkflow actualResponse = client.getMigrationWorkflow(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 getMigrationWorkflowExceptionTest2()266 public void getMigrationWorkflowExceptionTest2() 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-4710/locations/location-4710/workflows/workflow-4710"; 274 client.getMigrationWorkflow(name); 275 Assert.fail("No exception raised"); 276 } catch (InvalidArgumentException e) { 277 // Expected exception. 278 } 279 } 280 281 @Test listMigrationWorkflowsTest()282 public void listMigrationWorkflowsTest() throws Exception { 283 MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); 284 ListMigrationWorkflowsResponse expectedResponse = 285 ListMigrationWorkflowsResponse.newBuilder() 286 .setNextPageToken("") 287 .addAllMigrationWorkflows(Arrays.asList(responsesElement)) 288 .build(); 289 mockService.addResponse(expectedResponse); 290 291 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 292 293 ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); 294 295 List<MigrationWorkflow> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 296 297 Assert.assertEquals(1, resources.size()); 298 Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().get(0), resources.get(0)); 299 300 List<String> actualRequests = mockService.getRequestPaths(); 301 Assert.assertEquals(1, actualRequests.size()); 302 303 String apiClientHeaderKey = 304 mockService 305 .getRequestHeaders() 306 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 307 .iterator() 308 .next(); 309 Assert.assertTrue( 310 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 311 .matcher(apiClientHeaderKey) 312 .matches()); 313 } 314 315 @Test listMigrationWorkflowsExceptionTest()316 public void listMigrationWorkflowsExceptionTest() throws Exception { 317 ApiException exception = 318 ApiExceptionFactory.createException( 319 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 320 mockService.addException(exception); 321 322 try { 323 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 324 client.listMigrationWorkflows(parent); 325 Assert.fail("No exception raised"); 326 } catch (InvalidArgumentException e) { 327 // Expected exception. 328 } 329 } 330 331 @Test listMigrationWorkflowsTest2()332 public void listMigrationWorkflowsTest2() throws Exception { 333 MigrationWorkflow responsesElement = MigrationWorkflow.newBuilder().build(); 334 ListMigrationWorkflowsResponse expectedResponse = 335 ListMigrationWorkflowsResponse.newBuilder() 336 .setNextPageToken("") 337 .addAllMigrationWorkflows(Arrays.asList(responsesElement)) 338 .build(); 339 mockService.addResponse(expectedResponse); 340 341 String parent = "projects/project-5833/locations/location-5833"; 342 343 ListMigrationWorkflowsPagedResponse pagedListResponse = client.listMigrationWorkflows(parent); 344 345 List<MigrationWorkflow> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 346 347 Assert.assertEquals(1, resources.size()); 348 Assert.assertEquals(expectedResponse.getMigrationWorkflowsList().get(0), resources.get(0)); 349 350 List<String> actualRequests = mockService.getRequestPaths(); 351 Assert.assertEquals(1, actualRequests.size()); 352 353 String apiClientHeaderKey = 354 mockService 355 .getRequestHeaders() 356 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 357 .iterator() 358 .next(); 359 Assert.assertTrue( 360 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 361 .matcher(apiClientHeaderKey) 362 .matches()); 363 } 364 365 @Test listMigrationWorkflowsExceptionTest2()366 public void listMigrationWorkflowsExceptionTest2() throws Exception { 367 ApiException exception = 368 ApiExceptionFactory.createException( 369 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 370 mockService.addException(exception); 371 372 try { 373 String parent = "projects/project-5833/locations/location-5833"; 374 client.listMigrationWorkflows(parent); 375 Assert.fail("No exception raised"); 376 } catch (InvalidArgumentException e) { 377 // Expected exception. 378 } 379 } 380 381 @Test deleteMigrationWorkflowTest()382 public void deleteMigrationWorkflowTest() throws Exception { 383 Empty expectedResponse = Empty.newBuilder().build(); 384 mockService.addResponse(expectedResponse); 385 386 MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 387 388 client.deleteMigrationWorkflow(name); 389 390 List<String> actualRequests = mockService.getRequestPaths(); 391 Assert.assertEquals(1, actualRequests.size()); 392 393 String apiClientHeaderKey = 394 mockService 395 .getRequestHeaders() 396 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 397 .iterator() 398 .next(); 399 Assert.assertTrue( 400 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 401 .matcher(apiClientHeaderKey) 402 .matches()); 403 } 404 405 @Test deleteMigrationWorkflowExceptionTest()406 public void deleteMigrationWorkflowExceptionTest() throws Exception { 407 ApiException exception = 408 ApiExceptionFactory.createException( 409 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 410 mockService.addException(exception); 411 412 try { 413 MigrationWorkflowName name = 414 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 415 client.deleteMigrationWorkflow(name); 416 Assert.fail("No exception raised"); 417 } catch (InvalidArgumentException e) { 418 // Expected exception. 419 } 420 } 421 422 @Test deleteMigrationWorkflowTest2()423 public void deleteMigrationWorkflowTest2() throws Exception { 424 Empty expectedResponse = Empty.newBuilder().build(); 425 mockService.addResponse(expectedResponse); 426 427 String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; 428 429 client.deleteMigrationWorkflow(name); 430 431 List<String> actualRequests = mockService.getRequestPaths(); 432 Assert.assertEquals(1, actualRequests.size()); 433 434 String apiClientHeaderKey = 435 mockService 436 .getRequestHeaders() 437 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 438 .iterator() 439 .next(); 440 Assert.assertTrue( 441 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 442 .matcher(apiClientHeaderKey) 443 .matches()); 444 } 445 446 @Test deleteMigrationWorkflowExceptionTest2()447 public void deleteMigrationWorkflowExceptionTest2() throws Exception { 448 ApiException exception = 449 ApiExceptionFactory.createException( 450 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 451 mockService.addException(exception); 452 453 try { 454 String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; 455 client.deleteMigrationWorkflow(name); 456 Assert.fail("No exception raised"); 457 } catch (InvalidArgumentException e) { 458 // Expected exception. 459 } 460 } 461 462 @Test startMigrationWorkflowTest()463 public void startMigrationWorkflowTest() throws Exception { 464 Empty expectedResponse = Empty.newBuilder().build(); 465 mockService.addResponse(expectedResponse); 466 467 MigrationWorkflowName name = MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 468 469 client.startMigrationWorkflow(name); 470 471 List<String> actualRequests = mockService.getRequestPaths(); 472 Assert.assertEquals(1, actualRequests.size()); 473 474 String apiClientHeaderKey = 475 mockService 476 .getRequestHeaders() 477 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 478 .iterator() 479 .next(); 480 Assert.assertTrue( 481 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 482 .matcher(apiClientHeaderKey) 483 .matches()); 484 } 485 486 @Test startMigrationWorkflowExceptionTest()487 public void startMigrationWorkflowExceptionTest() throws Exception { 488 ApiException exception = 489 ApiExceptionFactory.createException( 490 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 491 mockService.addException(exception); 492 493 try { 494 MigrationWorkflowName name = 495 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 496 client.startMigrationWorkflow(name); 497 Assert.fail("No exception raised"); 498 } catch (InvalidArgumentException e) { 499 // Expected exception. 500 } 501 } 502 503 @Test startMigrationWorkflowTest2()504 public void startMigrationWorkflowTest2() throws Exception { 505 Empty expectedResponse = Empty.newBuilder().build(); 506 mockService.addResponse(expectedResponse); 507 508 String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; 509 510 client.startMigrationWorkflow(name); 511 512 List<String> actualRequests = mockService.getRequestPaths(); 513 Assert.assertEquals(1, actualRequests.size()); 514 515 String apiClientHeaderKey = 516 mockService 517 .getRequestHeaders() 518 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 519 .iterator() 520 .next(); 521 Assert.assertTrue( 522 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 523 .matcher(apiClientHeaderKey) 524 .matches()); 525 } 526 527 @Test startMigrationWorkflowExceptionTest2()528 public void startMigrationWorkflowExceptionTest2() throws Exception { 529 ApiException exception = 530 ApiExceptionFactory.createException( 531 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 532 mockService.addException(exception); 533 534 try { 535 String name = "projects/project-4710/locations/location-4710/workflows/workflow-4710"; 536 client.startMigrationWorkflow(name); 537 Assert.fail("No exception raised"); 538 } catch (InvalidArgumentException e) { 539 // Expected exception. 540 } 541 } 542 543 @Test getMigrationSubtaskTest()544 public void getMigrationSubtaskTest() throws Exception { 545 MigrationSubtask expectedResponse = 546 MigrationSubtask.newBuilder() 547 .setName( 548 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") 549 .toString()) 550 .setTaskId("taskId-880873088") 551 .setType("type3575610") 552 .setProcessingError(ErrorInfo.newBuilder().build()) 553 .addAllResourceErrorDetails(new ArrayList<ResourceErrorDetail>()) 554 .setResourceErrorCount(-929997465) 555 .setCreateTime(Timestamp.newBuilder().build()) 556 .setLastUpdateTime(Timestamp.newBuilder().build()) 557 .addAllMetrics(new ArrayList<TimeSeries>()) 558 .build(); 559 mockService.addResponse(expectedResponse); 560 561 MigrationSubtaskName name = 562 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); 563 564 MigrationSubtask actualResponse = client.getMigrationSubtask(name); 565 Assert.assertEquals(expectedResponse, actualResponse); 566 567 List<String> actualRequests = mockService.getRequestPaths(); 568 Assert.assertEquals(1, actualRequests.size()); 569 570 String apiClientHeaderKey = 571 mockService 572 .getRequestHeaders() 573 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 574 .iterator() 575 .next(); 576 Assert.assertTrue( 577 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 578 .matcher(apiClientHeaderKey) 579 .matches()); 580 } 581 582 @Test getMigrationSubtaskExceptionTest()583 public void getMigrationSubtaskExceptionTest() throws Exception { 584 ApiException exception = 585 ApiExceptionFactory.createException( 586 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 587 mockService.addException(exception); 588 589 try { 590 MigrationSubtaskName name = 591 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]"); 592 client.getMigrationSubtask(name); 593 Assert.fail("No exception raised"); 594 } catch (InvalidArgumentException e) { 595 // Expected exception. 596 } 597 } 598 599 @Test getMigrationSubtaskTest2()600 public void getMigrationSubtaskTest2() throws Exception { 601 MigrationSubtask expectedResponse = 602 MigrationSubtask.newBuilder() 603 .setName( 604 MigrationSubtaskName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]", "[SUBTASK]") 605 .toString()) 606 .setTaskId("taskId-880873088") 607 .setType("type3575610") 608 .setProcessingError(ErrorInfo.newBuilder().build()) 609 .addAllResourceErrorDetails(new ArrayList<ResourceErrorDetail>()) 610 .setResourceErrorCount(-929997465) 611 .setCreateTime(Timestamp.newBuilder().build()) 612 .setLastUpdateTime(Timestamp.newBuilder().build()) 613 .addAllMetrics(new ArrayList<TimeSeries>()) 614 .build(); 615 mockService.addResponse(expectedResponse); 616 617 String name = 618 "projects/project-3070/locations/location-3070/workflows/workflow-3070/subtasks/subtask-3070"; 619 620 MigrationSubtask actualResponse = client.getMigrationSubtask(name); 621 Assert.assertEquals(expectedResponse, actualResponse); 622 623 List<String> actualRequests = mockService.getRequestPaths(); 624 Assert.assertEquals(1, actualRequests.size()); 625 626 String apiClientHeaderKey = 627 mockService 628 .getRequestHeaders() 629 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 630 .iterator() 631 .next(); 632 Assert.assertTrue( 633 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 634 .matcher(apiClientHeaderKey) 635 .matches()); 636 } 637 638 @Test getMigrationSubtaskExceptionTest2()639 public void getMigrationSubtaskExceptionTest2() throws Exception { 640 ApiException exception = 641 ApiExceptionFactory.createException( 642 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 643 mockService.addException(exception); 644 645 try { 646 String name = 647 "projects/project-3070/locations/location-3070/workflows/workflow-3070/subtasks/subtask-3070"; 648 client.getMigrationSubtask(name); 649 Assert.fail("No exception raised"); 650 } catch (InvalidArgumentException e) { 651 // Expected exception. 652 } 653 } 654 655 @Test listMigrationSubtasksTest()656 public void listMigrationSubtasksTest() throws Exception { 657 MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); 658 ListMigrationSubtasksResponse expectedResponse = 659 ListMigrationSubtasksResponse.newBuilder() 660 .setNextPageToken("") 661 .addAllMigrationSubtasks(Arrays.asList(responsesElement)) 662 .build(); 663 mockService.addResponse(expectedResponse); 664 665 MigrationWorkflowName parent = 666 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 667 668 ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); 669 670 List<MigrationSubtask> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 671 672 Assert.assertEquals(1, resources.size()); 673 Assert.assertEquals(expectedResponse.getMigrationSubtasksList().get(0), resources.get(0)); 674 675 List<String> actualRequests = mockService.getRequestPaths(); 676 Assert.assertEquals(1, actualRequests.size()); 677 678 String apiClientHeaderKey = 679 mockService 680 .getRequestHeaders() 681 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 682 .iterator() 683 .next(); 684 Assert.assertTrue( 685 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 686 .matcher(apiClientHeaderKey) 687 .matches()); 688 } 689 690 @Test listMigrationSubtasksExceptionTest()691 public void listMigrationSubtasksExceptionTest() throws Exception { 692 ApiException exception = 693 ApiExceptionFactory.createException( 694 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 695 mockService.addException(exception); 696 697 try { 698 MigrationWorkflowName parent = 699 MigrationWorkflowName.of("[PROJECT]", "[LOCATION]", "[WORKFLOW]"); 700 client.listMigrationSubtasks(parent); 701 Assert.fail("No exception raised"); 702 } catch (InvalidArgumentException e) { 703 // Expected exception. 704 } 705 } 706 707 @Test listMigrationSubtasksTest2()708 public void listMigrationSubtasksTest2() throws Exception { 709 MigrationSubtask responsesElement = MigrationSubtask.newBuilder().build(); 710 ListMigrationSubtasksResponse expectedResponse = 711 ListMigrationSubtasksResponse.newBuilder() 712 .setNextPageToken("") 713 .addAllMigrationSubtasks(Arrays.asList(responsesElement)) 714 .build(); 715 mockService.addResponse(expectedResponse); 716 717 String parent = "projects/project-9319/locations/location-9319/workflows/workflow-9319"; 718 719 ListMigrationSubtasksPagedResponse pagedListResponse = client.listMigrationSubtasks(parent); 720 721 List<MigrationSubtask> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 722 723 Assert.assertEquals(1, resources.size()); 724 Assert.assertEquals(expectedResponse.getMigrationSubtasksList().get(0), resources.get(0)); 725 726 List<String> actualRequests = mockService.getRequestPaths(); 727 Assert.assertEquals(1, actualRequests.size()); 728 729 String apiClientHeaderKey = 730 mockService 731 .getRequestHeaders() 732 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 733 .iterator() 734 .next(); 735 Assert.assertTrue( 736 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 737 .matcher(apiClientHeaderKey) 738 .matches()); 739 } 740 741 @Test listMigrationSubtasksExceptionTest2()742 public void listMigrationSubtasksExceptionTest2() throws Exception { 743 ApiException exception = 744 ApiExceptionFactory.createException( 745 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 746 mockService.addException(exception); 747 748 try { 749 String parent = "projects/project-9319/locations/location-9319/workflows/workflow-9319"; 750 client.listMigrationSubtasks(parent); 751 Assert.fail("No exception raised"); 752 } catch (InvalidArgumentException e) { 753 // Expected exception. 754 } 755 } 756 } 757