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.dialogflow.cx.v3; 18 19 import static com.google.cloud.dialogflow.cx.v3.VersionsClient.ListLocationsPagedResponse; 20 import static com.google.cloud.dialogflow.cx.v3.VersionsClient.ListVersionsPagedResponse; 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.dialogflow.cx.v3.stub.HttpJsonVersionsStub; 32 import com.google.cloud.location.GetLocationRequest; 33 import com.google.cloud.location.ListLocationsRequest; 34 import com.google.cloud.location.ListLocationsResponse; 35 import com.google.cloud.location.Location; 36 import com.google.common.collect.Lists; 37 import com.google.longrunning.Operation; 38 import com.google.protobuf.Any; 39 import com.google.protobuf.Empty; 40 import com.google.protobuf.FieldMask; 41 import com.google.protobuf.Timestamp; 42 import java.io.IOException; 43 import java.util.Arrays; 44 import java.util.HashMap; 45 import java.util.List; 46 import java.util.concurrent.ExecutionException; 47 import javax.annotation.Generated; 48 import org.junit.After; 49 import org.junit.AfterClass; 50 import org.junit.Assert; 51 import org.junit.Before; 52 import org.junit.BeforeClass; 53 import org.junit.Test; 54 55 @Generated("by gapic-generator-java") 56 public class VersionsClientHttpJsonTest { 57 private static MockHttpService mockService; 58 private static VersionsClient client; 59 60 @BeforeClass startStaticServer()61 public static void startStaticServer() throws IOException { 62 mockService = 63 new MockHttpService( 64 HttpJsonVersionsStub.getMethodDescriptors(), VersionsSettings.getDefaultEndpoint()); 65 VersionsSettings settings = 66 VersionsSettings.newHttpJsonBuilder() 67 .setTransportChannelProvider( 68 VersionsSettings.defaultHttpJsonTransportProviderBuilder() 69 .setHttpTransport(mockService) 70 .build()) 71 .setCredentialsProvider(NoCredentialsProvider.create()) 72 .build(); 73 client = VersionsClient.create(settings); 74 } 75 76 @AfterClass stopServer()77 public static void stopServer() { 78 client.close(); 79 } 80 81 @Before setUp()82 public void setUp() {} 83 84 @After tearDown()85 public void tearDown() throws Exception { 86 mockService.reset(); 87 } 88 89 @Test listVersionsTest()90 public void listVersionsTest() throws Exception { 91 Version responsesElement = Version.newBuilder().build(); 92 ListVersionsResponse expectedResponse = 93 ListVersionsResponse.newBuilder() 94 .setNextPageToken("") 95 .addAllVersions(Arrays.asList(responsesElement)) 96 .build(); 97 mockService.addResponse(expectedResponse); 98 99 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 100 101 ListVersionsPagedResponse pagedListResponse = client.listVersions(parent); 102 103 List<Version> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 104 105 Assert.assertEquals(1, resources.size()); 106 Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0)); 107 108 List<String> actualRequests = mockService.getRequestPaths(); 109 Assert.assertEquals(1, actualRequests.size()); 110 111 String apiClientHeaderKey = 112 mockService 113 .getRequestHeaders() 114 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 115 .iterator() 116 .next(); 117 Assert.assertTrue( 118 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 119 .matcher(apiClientHeaderKey) 120 .matches()); 121 } 122 123 @Test listVersionsExceptionTest()124 public void listVersionsExceptionTest() throws Exception { 125 ApiException exception = 126 ApiExceptionFactory.createException( 127 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 128 mockService.addException(exception); 129 130 try { 131 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 132 client.listVersions(parent); 133 Assert.fail("No exception raised"); 134 } catch (InvalidArgumentException e) { 135 // Expected exception. 136 } 137 } 138 139 @Test listVersionsTest2()140 public void listVersionsTest2() throws Exception { 141 Version responsesElement = Version.newBuilder().build(); 142 ListVersionsResponse expectedResponse = 143 ListVersionsResponse.newBuilder() 144 .setNextPageToken("") 145 .addAllVersions(Arrays.asList(responsesElement)) 146 .build(); 147 mockService.addResponse(expectedResponse); 148 149 String parent = 150 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 151 152 ListVersionsPagedResponse pagedListResponse = client.listVersions(parent); 153 154 List<Version> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 155 156 Assert.assertEquals(1, resources.size()); 157 Assert.assertEquals(expectedResponse.getVersionsList().get(0), resources.get(0)); 158 159 List<String> actualRequests = mockService.getRequestPaths(); 160 Assert.assertEquals(1, actualRequests.size()); 161 162 String apiClientHeaderKey = 163 mockService 164 .getRequestHeaders() 165 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 166 .iterator() 167 .next(); 168 Assert.assertTrue( 169 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 170 .matcher(apiClientHeaderKey) 171 .matches()); 172 } 173 174 @Test listVersionsExceptionTest2()175 public void listVersionsExceptionTest2() throws Exception { 176 ApiException exception = 177 ApiExceptionFactory.createException( 178 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 179 mockService.addException(exception); 180 181 try { 182 String parent = 183 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 184 client.listVersions(parent); 185 Assert.fail("No exception raised"); 186 } catch (InvalidArgumentException e) { 187 // Expected exception. 188 } 189 } 190 191 @Test getVersionTest()192 public void getVersionTest() throws Exception { 193 Version expectedResponse = 194 Version.newBuilder() 195 .setName( 196 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 197 .toString()) 198 .setDisplayName("displayName1714148973") 199 .setDescription("description-1724546052") 200 .setNluSettings(NluSettings.newBuilder().build()) 201 .setCreateTime(Timestamp.newBuilder().build()) 202 .build(); 203 mockService.addResponse(expectedResponse); 204 205 VersionName name = VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 206 207 Version actualResponse = client.getVersion(name); 208 Assert.assertEquals(expectedResponse, actualResponse); 209 210 List<String> actualRequests = mockService.getRequestPaths(); 211 Assert.assertEquals(1, actualRequests.size()); 212 213 String apiClientHeaderKey = 214 mockService 215 .getRequestHeaders() 216 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 217 .iterator() 218 .next(); 219 Assert.assertTrue( 220 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 221 .matcher(apiClientHeaderKey) 222 .matches()); 223 } 224 225 @Test getVersionExceptionTest()226 public void getVersionExceptionTest() throws Exception { 227 ApiException exception = 228 ApiExceptionFactory.createException( 229 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 230 mockService.addException(exception); 231 232 try { 233 VersionName name = 234 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 235 client.getVersion(name); 236 Assert.fail("No exception raised"); 237 } catch (InvalidArgumentException e) { 238 // Expected exception. 239 } 240 } 241 242 @Test getVersionTest2()243 public void getVersionTest2() throws Exception { 244 Version expectedResponse = 245 Version.newBuilder() 246 .setName( 247 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 248 .toString()) 249 .setDisplayName("displayName1714148973") 250 .setDescription("description-1724546052") 251 .setNluSettings(NluSettings.newBuilder().build()) 252 .setCreateTime(Timestamp.newBuilder().build()) 253 .build(); 254 mockService.addResponse(expectedResponse); 255 256 String name = 257 "projects/project-3110/locations/location-3110/agents/agent-3110/flows/flow-3110/versions/version-3110"; 258 259 Version actualResponse = client.getVersion(name); 260 Assert.assertEquals(expectedResponse, actualResponse); 261 262 List<String> actualRequests = mockService.getRequestPaths(); 263 Assert.assertEquals(1, actualRequests.size()); 264 265 String apiClientHeaderKey = 266 mockService 267 .getRequestHeaders() 268 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 269 .iterator() 270 .next(); 271 Assert.assertTrue( 272 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 273 .matcher(apiClientHeaderKey) 274 .matches()); 275 } 276 277 @Test getVersionExceptionTest2()278 public void getVersionExceptionTest2() throws Exception { 279 ApiException exception = 280 ApiExceptionFactory.createException( 281 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 282 mockService.addException(exception); 283 284 try { 285 String name = 286 "projects/project-3110/locations/location-3110/agents/agent-3110/flows/flow-3110/versions/version-3110"; 287 client.getVersion(name); 288 Assert.fail("No exception raised"); 289 } catch (InvalidArgumentException e) { 290 // Expected exception. 291 } 292 } 293 294 @Test createVersionTest()295 public void createVersionTest() throws Exception { 296 Version expectedResponse = 297 Version.newBuilder() 298 .setName( 299 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 300 .toString()) 301 .setDisplayName("displayName1714148973") 302 .setDescription("description-1724546052") 303 .setNluSettings(NluSettings.newBuilder().build()) 304 .setCreateTime(Timestamp.newBuilder().build()) 305 .build(); 306 Operation resultOperation = 307 Operation.newBuilder() 308 .setName("createVersionTest") 309 .setDone(true) 310 .setResponse(Any.pack(expectedResponse)) 311 .build(); 312 mockService.addResponse(resultOperation); 313 314 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 315 Version version = Version.newBuilder().build(); 316 317 Version actualResponse = client.createVersionAsync(parent, version).get(); 318 Assert.assertEquals(expectedResponse, actualResponse); 319 320 List<String> actualRequests = mockService.getRequestPaths(); 321 Assert.assertEquals(1, actualRequests.size()); 322 323 String apiClientHeaderKey = 324 mockService 325 .getRequestHeaders() 326 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 327 .iterator() 328 .next(); 329 Assert.assertTrue( 330 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 331 .matcher(apiClientHeaderKey) 332 .matches()); 333 } 334 335 @Test createVersionExceptionTest()336 public void createVersionExceptionTest() throws Exception { 337 ApiException exception = 338 ApiExceptionFactory.createException( 339 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 340 mockService.addException(exception); 341 342 try { 343 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 344 Version version = Version.newBuilder().build(); 345 client.createVersionAsync(parent, version).get(); 346 Assert.fail("No exception raised"); 347 } catch (ExecutionException e) { 348 } 349 } 350 351 @Test createVersionTest2()352 public void createVersionTest2() throws Exception { 353 Version expectedResponse = 354 Version.newBuilder() 355 .setName( 356 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 357 .toString()) 358 .setDisplayName("displayName1714148973") 359 .setDescription("description-1724546052") 360 .setNluSettings(NluSettings.newBuilder().build()) 361 .setCreateTime(Timestamp.newBuilder().build()) 362 .build(); 363 Operation resultOperation = 364 Operation.newBuilder() 365 .setName("createVersionTest") 366 .setDone(true) 367 .setResponse(Any.pack(expectedResponse)) 368 .build(); 369 mockService.addResponse(resultOperation); 370 371 String parent = 372 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 373 Version version = Version.newBuilder().build(); 374 375 Version actualResponse = client.createVersionAsync(parent, version).get(); 376 Assert.assertEquals(expectedResponse, actualResponse); 377 378 List<String> actualRequests = mockService.getRequestPaths(); 379 Assert.assertEquals(1, actualRequests.size()); 380 381 String apiClientHeaderKey = 382 mockService 383 .getRequestHeaders() 384 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 385 .iterator() 386 .next(); 387 Assert.assertTrue( 388 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 389 .matcher(apiClientHeaderKey) 390 .matches()); 391 } 392 393 @Test createVersionExceptionTest2()394 public void createVersionExceptionTest2() throws Exception { 395 ApiException exception = 396 ApiExceptionFactory.createException( 397 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 398 mockService.addException(exception); 399 400 try { 401 String parent = 402 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 403 Version version = Version.newBuilder().build(); 404 client.createVersionAsync(parent, version).get(); 405 Assert.fail("No exception raised"); 406 } catch (ExecutionException e) { 407 } 408 } 409 410 @Test updateVersionTest()411 public void updateVersionTest() throws Exception { 412 Version expectedResponse = 413 Version.newBuilder() 414 .setName( 415 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 416 .toString()) 417 .setDisplayName("displayName1714148973") 418 .setDescription("description-1724546052") 419 .setNluSettings(NluSettings.newBuilder().build()) 420 .setCreateTime(Timestamp.newBuilder().build()) 421 .build(); 422 mockService.addResponse(expectedResponse); 423 424 Version version = 425 Version.newBuilder() 426 .setName( 427 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 428 .toString()) 429 .setDisplayName("displayName1714148973") 430 .setDescription("description-1724546052") 431 .setNluSettings(NluSettings.newBuilder().build()) 432 .setCreateTime(Timestamp.newBuilder().build()) 433 .build(); 434 FieldMask updateMask = FieldMask.newBuilder().build(); 435 436 Version actualResponse = client.updateVersion(version, updateMask); 437 Assert.assertEquals(expectedResponse, actualResponse); 438 439 List<String> actualRequests = mockService.getRequestPaths(); 440 Assert.assertEquals(1, actualRequests.size()); 441 442 String apiClientHeaderKey = 443 mockService 444 .getRequestHeaders() 445 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 446 .iterator() 447 .next(); 448 Assert.assertTrue( 449 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 450 .matcher(apiClientHeaderKey) 451 .matches()); 452 } 453 454 @Test updateVersionExceptionTest()455 public void updateVersionExceptionTest() throws Exception { 456 ApiException exception = 457 ApiExceptionFactory.createException( 458 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 459 mockService.addException(exception); 460 461 try { 462 Version version = 463 Version.newBuilder() 464 .setName( 465 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]") 466 .toString()) 467 .setDisplayName("displayName1714148973") 468 .setDescription("description-1724546052") 469 .setNluSettings(NluSettings.newBuilder().build()) 470 .setCreateTime(Timestamp.newBuilder().build()) 471 .build(); 472 FieldMask updateMask = FieldMask.newBuilder().build(); 473 client.updateVersion(version, updateMask); 474 Assert.fail("No exception raised"); 475 } catch (InvalidArgumentException e) { 476 // Expected exception. 477 } 478 } 479 480 @Test deleteVersionTest()481 public void deleteVersionTest() throws Exception { 482 Empty expectedResponse = Empty.newBuilder().build(); 483 mockService.addResponse(expectedResponse); 484 485 VersionName name = VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 486 487 client.deleteVersion(name); 488 489 List<String> actualRequests = mockService.getRequestPaths(); 490 Assert.assertEquals(1, actualRequests.size()); 491 492 String apiClientHeaderKey = 493 mockService 494 .getRequestHeaders() 495 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 496 .iterator() 497 .next(); 498 Assert.assertTrue( 499 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 500 .matcher(apiClientHeaderKey) 501 .matches()); 502 } 503 504 @Test deleteVersionExceptionTest()505 public void deleteVersionExceptionTest() throws Exception { 506 ApiException exception = 507 ApiExceptionFactory.createException( 508 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 509 mockService.addException(exception); 510 511 try { 512 VersionName name = 513 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 514 client.deleteVersion(name); 515 Assert.fail("No exception raised"); 516 } catch (InvalidArgumentException e) { 517 // Expected exception. 518 } 519 } 520 521 @Test deleteVersionTest2()522 public void deleteVersionTest2() throws Exception { 523 Empty expectedResponse = Empty.newBuilder().build(); 524 mockService.addResponse(expectedResponse); 525 526 String name = 527 "projects/project-3110/locations/location-3110/agents/agent-3110/flows/flow-3110/versions/version-3110"; 528 529 client.deleteVersion(name); 530 531 List<String> actualRequests = mockService.getRequestPaths(); 532 Assert.assertEquals(1, actualRequests.size()); 533 534 String apiClientHeaderKey = 535 mockService 536 .getRequestHeaders() 537 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 538 .iterator() 539 .next(); 540 Assert.assertTrue( 541 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 542 .matcher(apiClientHeaderKey) 543 .matches()); 544 } 545 546 @Test deleteVersionExceptionTest2()547 public void deleteVersionExceptionTest2() throws Exception { 548 ApiException exception = 549 ApiExceptionFactory.createException( 550 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 551 mockService.addException(exception); 552 553 try { 554 String name = 555 "projects/project-3110/locations/location-3110/agents/agent-3110/flows/flow-3110/versions/version-3110"; 556 client.deleteVersion(name); 557 Assert.fail("No exception raised"); 558 } catch (InvalidArgumentException e) { 559 // Expected exception. 560 } 561 } 562 563 @Test loadVersionTest()564 public void loadVersionTest() throws Exception { 565 Empty expectedResponse = Empty.newBuilder().build(); 566 Operation resultOperation = 567 Operation.newBuilder() 568 .setName("loadVersionTest") 569 .setDone(true) 570 .setResponse(Any.pack(expectedResponse)) 571 .build(); 572 mockService.addResponse(resultOperation); 573 574 VersionName name = VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 575 576 client.loadVersionAsync(name).get(); 577 578 List<String> actualRequests = mockService.getRequestPaths(); 579 Assert.assertEquals(1, actualRequests.size()); 580 581 String apiClientHeaderKey = 582 mockService 583 .getRequestHeaders() 584 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 585 .iterator() 586 .next(); 587 Assert.assertTrue( 588 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 589 .matcher(apiClientHeaderKey) 590 .matches()); 591 } 592 593 @Test loadVersionExceptionTest()594 public void loadVersionExceptionTest() throws Exception { 595 ApiException exception = 596 ApiExceptionFactory.createException( 597 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 598 mockService.addException(exception); 599 600 try { 601 VersionName name = 602 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 603 client.loadVersionAsync(name).get(); 604 Assert.fail("No exception raised"); 605 } catch (ExecutionException e) { 606 } 607 } 608 609 @Test loadVersionTest2()610 public void loadVersionTest2() throws Exception { 611 Empty expectedResponse = Empty.newBuilder().build(); 612 Operation resultOperation = 613 Operation.newBuilder() 614 .setName("loadVersionTest") 615 .setDone(true) 616 .setResponse(Any.pack(expectedResponse)) 617 .build(); 618 mockService.addResponse(resultOperation); 619 620 String name = 621 "projects/project-3110/locations/location-3110/agents/agent-3110/flows/flow-3110/versions/version-3110"; 622 623 client.loadVersionAsync(name).get(); 624 625 List<String> actualRequests = mockService.getRequestPaths(); 626 Assert.assertEquals(1, actualRequests.size()); 627 628 String apiClientHeaderKey = 629 mockService 630 .getRequestHeaders() 631 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 632 .iterator() 633 .next(); 634 Assert.assertTrue( 635 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 636 .matcher(apiClientHeaderKey) 637 .matches()); 638 } 639 640 @Test loadVersionExceptionTest2()641 public void loadVersionExceptionTest2() throws Exception { 642 ApiException exception = 643 ApiExceptionFactory.createException( 644 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 645 mockService.addException(exception); 646 647 try { 648 String name = 649 "projects/project-3110/locations/location-3110/agents/agent-3110/flows/flow-3110/versions/version-3110"; 650 client.loadVersionAsync(name).get(); 651 Assert.fail("No exception raised"); 652 } catch (ExecutionException e) { 653 } 654 } 655 656 @Test compareVersionsTest()657 public void compareVersionsTest() throws Exception { 658 CompareVersionsResponse expectedResponse = 659 CompareVersionsResponse.newBuilder() 660 .setBaseVersionContentJson("baseVersionContentJson-856795718") 661 .setTargetVersionContentJson("targetVersionContentJson813797498") 662 .setCompareTime(Timestamp.newBuilder().build()) 663 .build(); 664 mockService.addResponse(expectedResponse); 665 666 VersionName baseVersion = 667 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 668 669 CompareVersionsResponse actualResponse = client.compareVersions(baseVersion); 670 Assert.assertEquals(expectedResponse, actualResponse); 671 672 List<String> actualRequests = mockService.getRequestPaths(); 673 Assert.assertEquals(1, actualRequests.size()); 674 675 String apiClientHeaderKey = 676 mockService 677 .getRequestHeaders() 678 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 679 .iterator() 680 .next(); 681 Assert.assertTrue( 682 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 683 .matcher(apiClientHeaderKey) 684 .matches()); 685 } 686 687 @Test compareVersionsExceptionTest()688 public void compareVersionsExceptionTest() throws Exception { 689 ApiException exception = 690 ApiExceptionFactory.createException( 691 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 692 mockService.addException(exception); 693 694 try { 695 VersionName baseVersion = 696 VersionName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[VERSION]"); 697 client.compareVersions(baseVersion); 698 Assert.fail("No exception raised"); 699 } catch (InvalidArgumentException e) { 700 // Expected exception. 701 } 702 } 703 704 @Test compareVersionsTest2()705 public void compareVersionsTest2() throws Exception { 706 CompareVersionsResponse expectedResponse = 707 CompareVersionsResponse.newBuilder() 708 .setBaseVersionContentJson("baseVersionContentJson-856795718") 709 .setTargetVersionContentJson("targetVersionContentJson813797498") 710 .setCompareTime(Timestamp.newBuilder().build()) 711 .build(); 712 mockService.addResponse(expectedResponse); 713 714 String baseVersion = 715 "projects/project-9842/locations/location-9842/agents/agent-9842/flows/flow-9842/versions/version-9842"; 716 717 CompareVersionsResponse actualResponse = client.compareVersions(baseVersion); 718 Assert.assertEquals(expectedResponse, actualResponse); 719 720 List<String> actualRequests = mockService.getRequestPaths(); 721 Assert.assertEquals(1, actualRequests.size()); 722 723 String apiClientHeaderKey = 724 mockService 725 .getRequestHeaders() 726 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 727 .iterator() 728 .next(); 729 Assert.assertTrue( 730 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 731 .matcher(apiClientHeaderKey) 732 .matches()); 733 } 734 735 @Test compareVersionsExceptionTest2()736 public void compareVersionsExceptionTest2() throws Exception { 737 ApiException exception = 738 ApiExceptionFactory.createException( 739 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 740 mockService.addException(exception); 741 742 try { 743 String baseVersion = 744 "projects/project-9842/locations/location-9842/agents/agent-9842/flows/flow-9842/versions/version-9842"; 745 client.compareVersions(baseVersion); 746 Assert.fail("No exception raised"); 747 } catch (InvalidArgumentException e) { 748 // Expected exception. 749 } 750 } 751 752 @Test listLocationsTest()753 public void listLocationsTest() throws Exception { 754 Location responsesElement = Location.newBuilder().build(); 755 ListLocationsResponse expectedResponse = 756 ListLocationsResponse.newBuilder() 757 .setNextPageToken("") 758 .addAllLocations(Arrays.asList(responsesElement)) 759 .build(); 760 mockService.addResponse(expectedResponse); 761 762 ListLocationsRequest request = 763 ListLocationsRequest.newBuilder() 764 .setName("projects/project-3664") 765 .setFilter("filter-1274492040") 766 .setPageSize(883849137) 767 .setPageToken("pageToken873572522") 768 .build(); 769 770 ListLocationsPagedResponse pagedListResponse = client.listLocations(request); 771 772 List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 773 774 Assert.assertEquals(1, resources.size()); 775 Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0)); 776 777 List<String> actualRequests = mockService.getRequestPaths(); 778 Assert.assertEquals(1, actualRequests.size()); 779 780 String apiClientHeaderKey = 781 mockService 782 .getRequestHeaders() 783 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 784 .iterator() 785 .next(); 786 Assert.assertTrue( 787 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 788 .matcher(apiClientHeaderKey) 789 .matches()); 790 } 791 792 @Test listLocationsExceptionTest()793 public void listLocationsExceptionTest() throws Exception { 794 ApiException exception = 795 ApiExceptionFactory.createException( 796 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 797 mockService.addException(exception); 798 799 try { 800 ListLocationsRequest request = 801 ListLocationsRequest.newBuilder() 802 .setName("projects/project-3664") 803 .setFilter("filter-1274492040") 804 .setPageSize(883849137) 805 .setPageToken("pageToken873572522") 806 .build(); 807 client.listLocations(request); 808 Assert.fail("No exception raised"); 809 } catch (InvalidArgumentException e) { 810 // Expected exception. 811 } 812 } 813 814 @Test getLocationTest()815 public void getLocationTest() throws Exception { 816 Location expectedResponse = 817 Location.newBuilder() 818 .setName("name3373707") 819 .setLocationId("locationId1541836720") 820 .setDisplayName("displayName1714148973") 821 .putAllLabels(new HashMap<String, String>()) 822 .setMetadata(Any.newBuilder().build()) 823 .build(); 824 mockService.addResponse(expectedResponse); 825 826 GetLocationRequest request = 827 GetLocationRequest.newBuilder() 828 .setName("projects/project-9062/locations/location-9062") 829 .build(); 830 831 Location actualResponse = client.getLocation(request); 832 Assert.assertEquals(expectedResponse, actualResponse); 833 834 List<String> actualRequests = mockService.getRequestPaths(); 835 Assert.assertEquals(1, actualRequests.size()); 836 837 String apiClientHeaderKey = 838 mockService 839 .getRequestHeaders() 840 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 841 .iterator() 842 .next(); 843 Assert.assertTrue( 844 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 845 .matcher(apiClientHeaderKey) 846 .matches()); 847 } 848 849 @Test getLocationExceptionTest()850 public void getLocationExceptionTest() throws Exception { 851 ApiException exception = 852 ApiExceptionFactory.createException( 853 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 854 mockService.addException(exception); 855 856 try { 857 GetLocationRequest request = 858 GetLocationRequest.newBuilder() 859 .setName("projects/project-9062/locations/location-9062") 860 .build(); 861 client.getLocation(request); 862 Assert.fail("No exception raised"); 863 } catch (InvalidArgumentException e) { 864 // Expected exception. 865 } 866 } 867 } 868