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.v2; 18 19 import static com.google.cloud.dialogflow.v2.EntityTypesClient.ListEntityTypesPagedResponse; 20 import static com.google.cloud.dialogflow.v2.EntityTypesClient.ListLocationsPagedResponse; 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.v2.stub.HttpJsonEntityTypesStub; 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 java.io.IOException; 42 import java.util.ArrayList; 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 EntityTypesClientHttpJsonTest { 57 private static MockHttpService mockService; 58 private static EntityTypesClient client; 59 60 @BeforeClass startStaticServer()61 public static void startStaticServer() throws IOException { 62 mockService = 63 new MockHttpService( 64 HttpJsonEntityTypesStub.getMethodDescriptors(), 65 EntityTypesSettings.getDefaultEndpoint()); 66 EntityTypesSettings settings = 67 EntityTypesSettings.newHttpJsonBuilder() 68 .setTransportChannelProvider( 69 EntityTypesSettings.defaultHttpJsonTransportProviderBuilder() 70 .setHttpTransport(mockService) 71 .build()) 72 .setCredentialsProvider(NoCredentialsProvider.create()) 73 .build(); 74 client = EntityTypesClient.create(settings); 75 } 76 77 @AfterClass stopServer()78 public static void stopServer() { 79 client.close(); 80 } 81 82 @Before setUp()83 public void setUp() {} 84 85 @After tearDown()86 public void tearDown() throws Exception { 87 mockService.reset(); 88 } 89 90 @Test listEntityTypesTest()91 public void listEntityTypesTest() throws Exception { 92 EntityType responsesElement = EntityType.newBuilder().build(); 93 ListEntityTypesResponse expectedResponse = 94 ListEntityTypesResponse.newBuilder() 95 .setNextPageToken("") 96 .addAllEntityTypes(Arrays.asList(responsesElement)) 97 .build(); 98 mockService.addResponse(expectedResponse); 99 100 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 101 102 ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent); 103 104 List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 105 106 Assert.assertEquals(1, resources.size()); 107 Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0)); 108 109 List<String> actualRequests = mockService.getRequestPaths(); 110 Assert.assertEquals(1, actualRequests.size()); 111 112 String apiClientHeaderKey = 113 mockService 114 .getRequestHeaders() 115 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 116 .iterator() 117 .next(); 118 Assert.assertTrue( 119 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 120 .matcher(apiClientHeaderKey) 121 .matches()); 122 } 123 124 @Test listEntityTypesExceptionTest()125 public void listEntityTypesExceptionTest() throws Exception { 126 ApiException exception = 127 ApiExceptionFactory.createException( 128 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 129 mockService.addException(exception); 130 131 try { 132 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 133 client.listEntityTypes(parent); 134 Assert.fail("No exception raised"); 135 } catch (InvalidArgumentException e) { 136 // Expected exception. 137 } 138 } 139 140 @Test listEntityTypesTest2()141 public void listEntityTypesTest2() throws Exception { 142 EntityType responsesElement = EntityType.newBuilder().build(); 143 ListEntityTypesResponse expectedResponse = 144 ListEntityTypesResponse.newBuilder() 145 .setNextPageToken("") 146 .addAllEntityTypes(Arrays.asList(responsesElement)) 147 .build(); 148 mockService.addResponse(expectedResponse); 149 150 String parent = "projects/project-2469/agent"; 151 152 ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent); 153 154 List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 155 156 Assert.assertEquals(1, resources.size()); 157 Assert.assertEquals(expectedResponse.getEntityTypesList().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 listEntityTypesExceptionTest2()175 public void listEntityTypesExceptionTest2() 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 = "projects/project-2469/agent"; 183 client.listEntityTypes(parent); 184 Assert.fail("No exception raised"); 185 } catch (InvalidArgumentException e) { 186 // Expected exception. 187 } 188 } 189 190 @Test listEntityTypesTest3()191 public void listEntityTypesTest3() throws Exception { 192 EntityType responsesElement = EntityType.newBuilder().build(); 193 ListEntityTypesResponse expectedResponse = 194 ListEntityTypesResponse.newBuilder() 195 .setNextPageToken("") 196 .addAllEntityTypes(Arrays.asList(responsesElement)) 197 .build(); 198 mockService.addResponse(expectedResponse); 199 200 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 201 String languageCode = "languageCode-2092349083"; 202 203 ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent, languageCode); 204 205 List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 206 207 Assert.assertEquals(1, resources.size()); 208 Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0)); 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 listEntityTypesExceptionTest3()226 public void listEntityTypesExceptionTest3() 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 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 234 String languageCode = "languageCode-2092349083"; 235 client.listEntityTypes(parent, languageCode); 236 Assert.fail("No exception raised"); 237 } catch (InvalidArgumentException e) { 238 // Expected exception. 239 } 240 } 241 242 @Test listEntityTypesTest4()243 public void listEntityTypesTest4() throws Exception { 244 EntityType responsesElement = EntityType.newBuilder().build(); 245 ListEntityTypesResponse expectedResponse = 246 ListEntityTypesResponse.newBuilder() 247 .setNextPageToken("") 248 .addAllEntityTypes(Arrays.asList(responsesElement)) 249 .build(); 250 mockService.addResponse(expectedResponse); 251 252 String parent = "projects/project-2469/agent"; 253 String languageCode = "languageCode-2092349083"; 254 255 ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent, languageCode); 256 257 List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 258 259 Assert.assertEquals(1, resources.size()); 260 Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0)); 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 listEntityTypesExceptionTest4()278 public void listEntityTypesExceptionTest4() 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 parent = "projects/project-2469/agent"; 286 String languageCode = "languageCode-2092349083"; 287 client.listEntityTypes(parent, languageCode); 288 Assert.fail("No exception raised"); 289 } catch (InvalidArgumentException e) { 290 // Expected exception. 291 } 292 } 293 294 @Test getEntityTypeTest()295 public void getEntityTypeTest() throws Exception { 296 EntityType expectedResponse = 297 EntityType.newBuilder() 298 .setName( 299 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 300 .setDisplayName("displayName1714148973") 301 .addAllEntities(new ArrayList<EntityType.Entity>()) 302 .setEnableFuzzyExtraction(true) 303 .build(); 304 mockService.addResponse(expectedResponse); 305 306 EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 307 308 EntityType actualResponse = client.getEntityType(name); 309 Assert.assertEquals(expectedResponse, actualResponse); 310 311 List<String> actualRequests = mockService.getRequestPaths(); 312 Assert.assertEquals(1, actualRequests.size()); 313 314 String apiClientHeaderKey = 315 mockService 316 .getRequestHeaders() 317 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 318 .iterator() 319 .next(); 320 Assert.assertTrue( 321 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 322 .matcher(apiClientHeaderKey) 323 .matches()); 324 } 325 326 @Test getEntityTypeExceptionTest()327 public void getEntityTypeExceptionTest() throws Exception { 328 ApiException exception = 329 ApiExceptionFactory.createException( 330 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 331 mockService.addException(exception); 332 333 try { 334 EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 335 client.getEntityType(name); 336 Assert.fail("No exception raised"); 337 } catch (InvalidArgumentException e) { 338 // Expected exception. 339 } 340 } 341 342 @Test getEntityTypeTest2()343 public void getEntityTypeTest2() throws Exception { 344 EntityType expectedResponse = 345 EntityType.newBuilder() 346 .setName( 347 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 348 .setDisplayName("displayName1714148973") 349 .addAllEntities(new ArrayList<EntityType.Entity>()) 350 .setEnableFuzzyExtraction(true) 351 .build(); 352 mockService.addResponse(expectedResponse); 353 354 String name = "projects/project-3464/agent/entityTypes/entityType-3464"; 355 356 EntityType actualResponse = client.getEntityType(name); 357 Assert.assertEquals(expectedResponse, actualResponse); 358 359 List<String> actualRequests = mockService.getRequestPaths(); 360 Assert.assertEquals(1, actualRequests.size()); 361 362 String apiClientHeaderKey = 363 mockService 364 .getRequestHeaders() 365 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 366 .iterator() 367 .next(); 368 Assert.assertTrue( 369 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 370 .matcher(apiClientHeaderKey) 371 .matches()); 372 } 373 374 @Test getEntityTypeExceptionTest2()375 public void getEntityTypeExceptionTest2() throws Exception { 376 ApiException exception = 377 ApiExceptionFactory.createException( 378 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 379 mockService.addException(exception); 380 381 try { 382 String name = "projects/project-3464/agent/entityTypes/entityType-3464"; 383 client.getEntityType(name); 384 Assert.fail("No exception raised"); 385 } catch (InvalidArgumentException e) { 386 // Expected exception. 387 } 388 } 389 390 @Test getEntityTypeTest3()391 public void getEntityTypeTest3() throws Exception { 392 EntityType expectedResponse = 393 EntityType.newBuilder() 394 .setName( 395 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 396 .setDisplayName("displayName1714148973") 397 .addAllEntities(new ArrayList<EntityType.Entity>()) 398 .setEnableFuzzyExtraction(true) 399 .build(); 400 mockService.addResponse(expectedResponse); 401 402 EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 403 String languageCode = "languageCode-2092349083"; 404 405 EntityType actualResponse = client.getEntityType(name, languageCode); 406 Assert.assertEquals(expectedResponse, actualResponse); 407 408 List<String> actualRequests = mockService.getRequestPaths(); 409 Assert.assertEquals(1, actualRequests.size()); 410 411 String apiClientHeaderKey = 412 mockService 413 .getRequestHeaders() 414 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 415 .iterator() 416 .next(); 417 Assert.assertTrue( 418 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 419 .matcher(apiClientHeaderKey) 420 .matches()); 421 } 422 423 @Test getEntityTypeExceptionTest3()424 public void getEntityTypeExceptionTest3() throws Exception { 425 ApiException exception = 426 ApiExceptionFactory.createException( 427 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 428 mockService.addException(exception); 429 430 try { 431 EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 432 String languageCode = "languageCode-2092349083"; 433 client.getEntityType(name, languageCode); 434 Assert.fail("No exception raised"); 435 } catch (InvalidArgumentException e) { 436 // Expected exception. 437 } 438 } 439 440 @Test getEntityTypeTest4()441 public void getEntityTypeTest4() throws Exception { 442 EntityType expectedResponse = 443 EntityType.newBuilder() 444 .setName( 445 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 446 .setDisplayName("displayName1714148973") 447 .addAllEntities(new ArrayList<EntityType.Entity>()) 448 .setEnableFuzzyExtraction(true) 449 .build(); 450 mockService.addResponse(expectedResponse); 451 452 String name = "projects/project-3464/agent/entityTypes/entityType-3464"; 453 String languageCode = "languageCode-2092349083"; 454 455 EntityType actualResponse = client.getEntityType(name, languageCode); 456 Assert.assertEquals(expectedResponse, actualResponse); 457 458 List<String> actualRequests = mockService.getRequestPaths(); 459 Assert.assertEquals(1, actualRequests.size()); 460 461 String apiClientHeaderKey = 462 mockService 463 .getRequestHeaders() 464 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 465 .iterator() 466 .next(); 467 Assert.assertTrue( 468 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 469 .matcher(apiClientHeaderKey) 470 .matches()); 471 } 472 473 @Test getEntityTypeExceptionTest4()474 public void getEntityTypeExceptionTest4() throws Exception { 475 ApiException exception = 476 ApiExceptionFactory.createException( 477 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 478 mockService.addException(exception); 479 480 try { 481 String name = "projects/project-3464/agent/entityTypes/entityType-3464"; 482 String languageCode = "languageCode-2092349083"; 483 client.getEntityType(name, languageCode); 484 Assert.fail("No exception raised"); 485 } catch (InvalidArgumentException e) { 486 // Expected exception. 487 } 488 } 489 490 @Test createEntityTypeTest()491 public void createEntityTypeTest() throws Exception { 492 EntityType expectedResponse = 493 EntityType.newBuilder() 494 .setName( 495 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 496 .setDisplayName("displayName1714148973") 497 .addAllEntities(new ArrayList<EntityType.Entity>()) 498 .setEnableFuzzyExtraction(true) 499 .build(); 500 mockService.addResponse(expectedResponse); 501 502 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 503 EntityType entityType = EntityType.newBuilder().build(); 504 505 EntityType actualResponse = client.createEntityType(parent, entityType); 506 Assert.assertEquals(expectedResponse, actualResponse); 507 508 List<String> actualRequests = mockService.getRequestPaths(); 509 Assert.assertEquals(1, actualRequests.size()); 510 511 String apiClientHeaderKey = 512 mockService 513 .getRequestHeaders() 514 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 515 .iterator() 516 .next(); 517 Assert.assertTrue( 518 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 519 .matcher(apiClientHeaderKey) 520 .matches()); 521 } 522 523 @Test createEntityTypeExceptionTest()524 public void createEntityTypeExceptionTest() throws Exception { 525 ApiException exception = 526 ApiExceptionFactory.createException( 527 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 528 mockService.addException(exception); 529 530 try { 531 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 532 EntityType entityType = EntityType.newBuilder().build(); 533 client.createEntityType(parent, entityType); 534 Assert.fail("No exception raised"); 535 } catch (InvalidArgumentException e) { 536 // Expected exception. 537 } 538 } 539 540 @Test createEntityTypeTest2()541 public void createEntityTypeTest2() throws Exception { 542 EntityType expectedResponse = 543 EntityType.newBuilder() 544 .setName( 545 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 546 .setDisplayName("displayName1714148973") 547 .addAllEntities(new ArrayList<EntityType.Entity>()) 548 .setEnableFuzzyExtraction(true) 549 .build(); 550 mockService.addResponse(expectedResponse); 551 552 String parent = "projects/project-2469/agent"; 553 EntityType entityType = EntityType.newBuilder().build(); 554 555 EntityType actualResponse = client.createEntityType(parent, entityType); 556 Assert.assertEquals(expectedResponse, actualResponse); 557 558 List<String> actualRequests = mockService.getRequestPaths(); 559 Assert.assertEquals(1, actualRequests.size()); 560 561 String apiClientHeaderKey = 562 mockService 563 .getRequestHeaders() 564 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 565 .iterator() 566 .next(); 567 Assert.assertTrue( 568 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 569 .matcher(apiClientHeaderKey) 570 .matches()); 571 } 572 573 @Test createEntityTypeExceptionTest2()574 public void createEntityTypeExceptionTest2() throws Exception { 575 ApiException exception = 576 ApiExceptionFactory.createException( 577 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 578 mockService.addException(exception); 579 580 try { 581 String parent = "projects/project-2469/agent"; 582 EntityType entityType = EntityType.newBuilder().build(); 583 client.createEntityType(parent, entityType); 584 Assert.fail("No exception raised"); 585 } catch (InvalidArgumentException e) { 586 // Expected exception. 587 } 588 } 589 590 @Test createEntityTypeTest3()591 public void createEntityTypeTest3() throws Exception { 592 EntityType expectedResponse = 593 EntityType.newBuilder() 594 .setName( 595 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 596 .setDisplayName("displayName1714148973") 597 .addAllEntities(new ArrayList<EntityType.Entity>()) 598 .setEnableFuzzyExtraction(true) 599 .build(); 600 mockService.addResponse(expectedResponse); 601 602 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 603 EntityType entityType = EntityType.newBuilder().build(); 604 String languageCode = "languageCode-2092349083"; 605 606 EntityType actualResponse = client.createEntityType(parent, entityType, languageCode); 607 Assert.assertEquals(expectedResponse, actualResponse); 608 609 List<String> actualRequests = mockService.getRequestPaths(); 610 Assert.assertEquals(1, actualRequests.size()); 611 612 String apiClientHeaderKey = 613 mockService 614 .getRequestHeaders() 615 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 616 .iterator() 617 .next(); 618 Assert.assertTrue( 619 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 620 .matcher(apiClientHeaderKey) 621 .matches()); 622 } 623 624 @Test createEntityTypeExceptionTest3()625 public void createEntityTypeExceptionTest3() throws Exception { 626 ApiException exception = 627 ApiExceptionFactory.createException( 628 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 629 mockService.addException(exception); 630 631 try { 632 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 633 EntityType entityType = EntityType.newBuilder().build(); 634 String languageCode = "languageCode-2092349083"; 635 client.createEntityType(parent, entityType, languageCode); 636 Assert.fail("No exception raised"); 637 } catch (InvalidArgumentException e) { 638 // Expected exception. 639 } 640 } 641 642 @Test createEntityTypeTest4()643 public void createEntityTypeTest4() throws Exception { 644 EntityType expectedResponse = 645 EntityType.newBuilder() 646 .setName( 647 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 648 .setDisplayName("displayName1714148973") 649 .addAllEntities(new ArrayList<EntityType.Entity>()) 650 .setEnableFuzzyExtraction(true) 651 .build(); 652 mockService.addResponse(expectedResponse); 653 654 String parent = "projects/project-2469/agent"; 655 EntityType entityType = EntityType.newBuilder().build(); 656 String languageCode = "languageCode-2092349083"; 657 658 EntityType actualResponse = client.createEntityType(parent, entityType, languageCode); 659 Assert.assertEquals(expectedResponse, actualResponse); 660 661 List<String> actualRequests = mockService.getRequestPaths(); 662 Assert.assertEquals(1, actualRequests.size()); 663 664 String apiClientHeaderKey = 665 mockService 666 .getRequestHeaders() 667 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 668 .iterator() 669 .next(); 670 Assert.assertTrue( 671 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 672 .matcher(apiClientHeaderKey) 673 .matches()); 674 } 675 676 @Test createEntityTypeExceptionTest4()677 public void createEntityTypeExceptionTest4() throws Exception { 678 ApiException exception = 679 ApiExceptionFactory.createException( 680 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 681 mockService.addException(exception); 682 683 try { 684 String parent = "projects/project-2469/agent"; 685 EntityType entityType = EntityType.newBuilder().build(); 686 String languageCode = "languageCode-2092349083"; 687 client.createEntityType(parent, entityType, languageCode); 688 Assert.fail("No exception raised"); 689 } catch (InvalidArgumentException e) { 690 // Expected exception. 691 } 692 } 693 694 @Test updateEntityTypeTest()695 public void updateEntityTypeTest() throws Exception { 696 EntityType expectedResponse = 697 EntityType.newBuilder() 698 .setName( 699 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 700 .setDisplayName("displayName1714148973") 701 .addAllEntities(new ArrayList<EntityType.Entity>()) 702 .setEnableFuzzyExtraction(true) 703 .build(); 704 mockService.addResponse(expectedResponse); 705 706 EntityType entityType = 707 EntityType.newBuilder() 708 .setName( 709 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 710 .setDisplayName("displayName1714148973") 711 .addAllEntities(new ArrayList<EntityType.Entity>()) 712 .setEnableFuzzyExtraction(true) 713 .build(); 714 715 EntityType actualResponse = client.updateEntityType(entityType); 716 Assert.assertEquals(expectedResponse, actualResponse); 717 718 List<String> actualRequests = mockService.getRequestPaths(); 719 Assert.assertEquals(1, actualRequests.size()); 720 721 String apiClientHeaderKey = 722 mockService 723 .getRequestHeaders() 724 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 725 .iterator() 726 .next(); 727 Assert.assertTrue( 728 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 729 .matcher(apiClientHeaderKey) 730 .matches()); 731 } 732 733 @Test updateEntityTypeExceptionTest()734 public void updateEntityTypeExceptionTest() throws Exception { 735 ApiException exception = 736 ApiExceptionFactory.createException( 737 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 738 mockService.addException(exception); 739 740 try { 741 EntityType entityType = 742 EntityType.newBuilder() 743 .setName( 744 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 745 .setDisplayName("displayName1714148973") 746 .addAllEntities(new ArrayList<EntityType.Entity>()) 747 .setEnableFuzzyExtraction(true) 748 .build(); 749 client.updateEntityType(entityType); 750 Assert.fail("No exception raised"); 751 } catch (InvalidArgumentException e) { 752 // Expected exception. 753 } 754 } 755 756 @Test updateEntityTypeTest2()757 public void updateEntityTypeTest2() throws Exception { 758 EntityType expectedResponse = 759 EntityType.newBuilder() 760 .setName( 761 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 762 .setDisplayName("displayName1714148973") 763 .addAllEntities(new ArrayList<EntityType.Entity>()) 764 .setEnableFuzzyExtraction(true) 765 .build(); 766 mockService.addResponse(expectedResponse); 767 768 EntityType entityType = 769 EntityType.newBuilder() 770 .setName( 771 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 772 .setDisplayName("displayName1714148973") 773 .addAllEntities(new ArrayList<EntityType.Entity>()) 774 .setEnableFuzzyExtraction(true) 775 .build(); 776 String languageCode = "languageCode-2092349083"; 777 778 EntityType actualResponse = client.updateEntityType(entityType, languageCode); 779 Assert.assertEquals(expectedResponse, actualResponse); 780 781 List<String> actualRequests = mockService.getRequestPaths(); 782 Assert.assertEquals(1, actualRequests.size()); 783 784 String apiClientHeaderKey = 785 mockService 786 .getRequestHeaders() 787 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 788 .iterator() 789 .next(); 790 Assert.assertTrue( 791 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 792 .matcher(apiClientHeaderKey) 793 .matches()); 794 } 795 796 @Test updateEntityTypeExceptionTest2()797 public void updateEntityTypeExceptionTest2() throws Exception { 798 ApiException exception = 799 ApiExceptionFactory.createException( 800 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 801 mockService.addException(exception); 802 803 try { 804 EntityType entityType = 805 EntityType.newBuilder() 806 .setName( 807 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString()) 808 .setDisplayName("displayName1714148973") 809 .addAllEntities(new ArrayList<EntityType.Entity>()) 810 .setEnableFuzzyExtraction(true) 811 .build(); 812 String languageCode = "languageCode-2092349083"; 813 client.updateEntityType(entityType, languageCode); 814 Assert.fail("No exception raised"); 815 } catch (InvalidArgumentException e) { 816 // Expected exception. 817 } 818 } 819 820 @Test deleteEntityTypeTest()821 public void deleteEntityTypeTest() throws Exception { 822 Empty expectedResponse = Empty.newBuilder().build(); 823 mockService.addResponse(expectedResponse); 824 825 EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 826 827 client.deleteEntityType(name); 828 829 List<String> actualRequests = mockService.getRequestPaths(); 830 Assert.assertEquals(1, actualRequests.size()); 831 832 String apiClientHeaderKey = 833 mockService 834 .getRequestHeaders() 835 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 836 .iterator() 837 .next(); 838 Assert.assertTrue( 839 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 840 .matcher(apiClientHeaderKey) 841 .matches()); 842 } 843 844 @Test deleteEntityTypeExceptionTest()845 public void deleteEntityTypeExceptionTest() throws Exception { 846 ApiException exception = 847 ApiExceptionFactory.createException( 848 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 849 mockService.addException(exception); 850 851 try { 852 EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 853 client.deleteEntityType(name); 854 Assert.fail("No exception raised"); 855 } catch (InvalidArgumentException e) { 856 // Expected exception. 857 } 858 } 859 860 @Test deleteEntityTypeTest2()861 public void deleteEntityTypeTest2() throws Exception { 862 Empty expectedResponse = Empty.newBuilder().build(); 863 mockService.addResponse(expectedResponse); 864 865 String name = "projects/project-3464/agent/entityTypes/entityType-3464"; 866 867 client.deleteEntityType(name); 868 869 List<String> actualRequests = mockService.getRequestPaths(); 870 Assert.assertEquals(1, actualRequests.size()); 871 872 String apiClientHeaderKey = 873 mockService 874 .getRequestHeaders() 875 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 876 .iterator() 877 .next(); 878 Assert.assertTrue( 879 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 880 .matcher(apiClientHeaderKey) 881 .matches()); 882 } 883 884 @Test deleteEntityTypeExceptionTest2()885 public void deleteEntityTypeExceptionTest2() throws Exception { 886 ApiException exception = 887 ApiExceptionFactory.createException( 888 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 889 mockService.addException(exception); 890 891 try { 892 String name = "projects/project-3464/agent/entityTypes/entityType-3464"; 893 client.deleteEntityType(name); 894 Assert.fail("No exception raised"); 895 } catch (InvalidArgumentException e) { 896 // Expected exception. 897 } 898 } 899 900 @Test batchUpdateEntityTypesTest()901 public void batchUpdateEntityTypesTest() throws Exception { 902 BatchUpdateEntityTypesResponse expectedResponse = 903 BatchUpdateEntityTypesResponse.newBuilder() 904 .addAllEntityTypes(new ArrayList<EntityType>()) 905 .build(); 906 Operation resultOperation = 907 Operation.newBuilder() 908 .setName("batchUpdateEntityTypesTest") 909 .setDone(true) 910 .setResponse(Any.pack(expectedResponse)) 911 .build(); 912 mockService.addResponse(resultOperation); 913 914 BatchUpdateEntityTypesRequest request = 915 BatchUpdateEntityTypesRequest.newBuilder() 916 .setParent(AgentName.ofProjectName("[PROJECT]").toString()) 917 .setLanguageCode("languageCode-2092349083") 918 .setUpdateMask(FieldMask.newBuilder().build()) 919 .build(); 920 921 BatchUpdateEntityTypesResponse actualResponse = 922 client.batchUpdateEntityTypesAsync(request).get(); 923 Assert.assertEquals(expectedResponse, actualResponse); 924 925 List<String> actualRequests = mockService.getRequestPaths(); 926 Assert.assertEquals(1, actualRequests.size()); 927 928 String apiClientHeaderKey = 929 mockService 930 .getRequestHeaders() 931 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 932 .iterator() 933 .next(); 934 Assert.assertTrue( 935 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 936 .matcher(apiClientHeaderKey) 937 .matches()); 938 } 939 940 @Test batchUpdateEntityTypesExceptionTest()941 public void batchUpdateEntityTypesExceptionTest() throws Exception { 942 ApiException exception = 943 ApiExceptionFactory.createException( 944 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 945 mockService.addException(exception); 946 947 try { 948 BatchUpdateEntityTypesRequest request = 949 BatchUpdateEntityTypesRequest.newBuilder() 950 .setParent(AgentName.ofProjectName("[PROJECT]").toString()) 951 .setLanguageCode("languageCode-2092349083") 952 .setUpdateMask(FieldMask.newBuilder().build()) 953 .build(); 954 client.batchUpdateEntityTypesAsync(request).get(); 955 Assert.fail("No exception raised"); 956 } catch (ExecutionException e) { 957 } 958 } 959 960 @Test batchDeleteEntityTypesTest()961 public void batchDeleteEntityTypesTest() throws Exception { 962 Empty expectedResponse = Empty.newBuilder().build(); 963 Operation resultOperation = 964 Operation.newBuilder() 965 .setName("batchDeleteEntityTypesTest") 966 .setDone(true) 967 .setResponse(Any.pack(expectedResponse)) 968 .build(); 969 mockService.addResponse(resultOperation); 970 971 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 972 List<String> entityTypeNames = new ArrayList<>(); 973 974 client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get(); 975 976 List<String> actualRequests = mockService.getRequestPaths(); 977 Assert.assertEquals(1, actualRequests.size()); 978 979 String apiClientHeaderKey = 980 mockService 981 .getRequestHeaders() 982 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 983 .iterator() 984 .next(); 985 Assert.assertTrue( 986 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 987 .matcher(apiClientHeaderKey) 988 .matches()); 989 } 990 991 @Test batchDeleteEntityTypesExceptionTest()992 public void batchDeleteEntityTypesExceptionTest() throws Exception { 993 ApiException exception = 994 ApiExceptionFactory.createException( 995 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 996 mockService.addException(exception); 997 998 try { 999 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1000 List<String> entityTypeNames = new ArrayList<>(); 1001 client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get(); 1002 Assert.fail("No exception raised"); 1003 } catch (ExecutionException e) { 1004 } 1005 } 1006 1007 @Test batchDeleteEntityTypesTest2()1008 public void batchDeleteEntityTypesTest2() throws Exception { 1009 Empty expectedResponse = Empty.newBuilder().build(); 1010 Operation resultOperation = 1011 Operation.newBuilder() 1012 .setName("batchDeleteEntityTypesTest") 1013 .setDone(true) 1014 .setResponse(Any.pack(expectedResponse)) 1015 .build(); 1016 mockService.addResponse(resultOperation); 1017 1018 String parent = "projects/project-2469/agent"; 1019 List<String> entityTypeNames = new ArrayList<>(); 1020 1021 client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get(); 1022 1023 List<String> actualRequests = mockService.getRequestPaths(); 1024 Assert.assertEquals(1, actualRequests.size()); 1025 1026 String apiClientHeaderKey = 1027 mockService 1028 .getRequestHeaders() 1029 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1030 .iterator() 1031 .next(); 1032 Assert.assertTrue( 1033 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1034 .matcher(apiClientHeaderKey) 1035 .matches()); 1036 } 1037 1038 @Test batchDeleteEntityTypesExceptionTest2()1039 public void batchDeleteEntityTypesExceptionTest2() throws Exception { 1040 ApiException exception = 1041 ApiExceptionFactory.createException( 1042 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1043 mockService.addException(exception); 1044 1045 try { 1046 String parent = "projects/project-2469/agent"; 1047 List<String> entityTypeNames = new ArrayList<>(); 1048 client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get(); 1049 Assert.fail("No exception raised"); 1050 } catch (ExecutionException e) { 1051 } 1052 } 1053 1054 @Test batchCreateEntitiesTest()1055 public void batchCreateEntitiesTest() throws Exception { 1056 Empty expectedResponse = Empty.newBuilder().build(); 1057 Operation resultOperation = 1058 Operation.newBuilder() 1059 .setName("batchCreateEntitiesTest") 1060 .setDone(true) 1061 .setResponse(Any.pack(expectedResponse)) 1062 .build(); 1063 mockService.addResponse(resultOperation); 1064 1065 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1066 List<EntityType.Entity> entities = new ArrayList<>(); 1067 1068 client.batchCreateEntitiesAsync(parent, entities).get(); 1069 1070 List<String> actualRequests = mockService.getRequestPaths(); 1071 Assert.assertEquals(1, actualRequests.size()); 1072 1073 String apiClientHeaderKey = 1074 mockService 1075 .getRequestHeaders() 1076 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1077 .iterator() 1078 .next(); 1079 Assert.assertTrue( 1080 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1081 .matcher(apiClientHeaderKey) 1082 .matches()); 1083 } 1084 1085 @Test batchCreateEntitiesExceptionTest()1086 public void batchCreateEntitiesExceptionTest() throws Exception { 1087 ApiException exception = 1088 ApiExceptionFactory.createException( 1089 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1090 mockService.addException(exception); 1091 1092 try { 1093 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1094 List<EntityType.Entity> entities = new ArrayList<>(); 1095 client.batchCreateEntitiesAsync(parent, entities).get(); 1096 Assert.fail("No exception raised"); 1097 } catch (ExecutionException e) { 1098 } 1099 } 1100 1101 @Test batchCreateEntitiesTest2()1102 public void batchCreateEntitiesTest2() throws Exception { 1103 Empty expectedResponse = Empty.newBuilder().build(); 1104 Operation resultOperation = 1105 Operation.newBuilder() 1106 .setName("batchCreateEntitiesTest") 1107 .setDone(true) 1108 .setResponse(Any.pack(expectedResponse)) 1109 .build(); 1110 mockService.addResponse(resultOperation); 1111 1112 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1113 List<EntityType.Entity> entities = new ArrayList<>(); 1114 1115 client.batchCreateEntitiesAsync(parent, entities).get(); 1116 1117 List<String> actualRequests = mockService.getRequestPaths(); 1118 Assert.assertEquals(1, actualRequests.size()); 1119 1120 String apiClientHeaderKey = 1121 mockService 1122 .getRequestHeaders() 1123 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1124 .iterator() 1125 .next(); 1126 Assert.assertTrue( 1127 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1128 .matcher(apiClientHeaderKey) 1129 .matches()); 1130 } 1131 1132 @Test batchCreateEntitiesExceptionTest2()1133 public void batchCreateEntitiesExceptionTest2() throws Exception { 1134 ApiException exception = 1135 ApiExceptionFactory.createException( 1136 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1137 mockService.addException(exception); 1138 1139 try { 1140 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1141 List<EntityType.Entity> entities = new ArrayList<>(); 1142 client.batchCreateEntitiesAsync(parent, entities).get(); 1143 Assert.fail("No exception raised"); 1144 } catch (ExecutionException e) { 1145 } 1146 } 1147 1148 @Test batchCreateEntitiesTest3()1149 public void batchCreateEntitiesTest3() throws Exception { 1150 Empty expectedResponse = Empty.newBuilder().build(); 1151 Operation resultOperation = 1152 Operation.newBuilder() 1153 .setName("batchCreateEntitiesTest") 1154 .setDone(true) 1155 .setResponse(Any.pack(expectedResponse)) 1156 .build(); 1157 mockService.addResponse(resultOperation); 1158 1159 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1160 List<EntityType.Entity> entities = new ArrayList<>(); 1161 String languageCode = "languageCode-2092349083"; 1162 1163 client.batchCreateEntitiesAsync(parent, entities, languageCode).get(); 1164 1165 List<String> actualRequests = mockService.getRequestPaths(); 1166 Assert.assertEquals(1, actualRequests.size()); 1167 1168 String apiClientHeaderKey = 1169 mockService 1170 .getRequestHeaders() 1171 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1172 .iterator() 1173 .next(); 1174 Assert.assertTrue( 1175 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1176 .matcher(apiClientHeaderKey) 1177 .matches()); 1178 } 1179 1180 @Test batchCreateEntitiesExceptionTest3()1181 public void batchCreateEntitiesExceptionTest3() throws Exception { 1182 ApiException exception = 1183 ApiExceptionFactory.createException( 1184 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1185 mockService.addException(exception); 1186 1187 try { 1188 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1189 List<EntityType.Entity> entities = new ArrayList<>(); 1190 String languageCode = "languageCode-2092349083"; 1191 client.batchCreateEntitiesAsync(parent, entities, languageCode).get(); 1192 Assert.fail("No exception raised"); 1193 } catch (ExecutionException e) { 1194 } 1195 } 1196 1197 @Test batchCreateEntitiesTest4()1198 public void batchCreateEntitiesTest4() throws Exception { 1199 Empty expectedResponse = Empty.newBuilder().build(); 1200 Operation resultOperation = 1201 Operation.newBuilder() 1202 .setName("batchCreateEntitiesTest") 1203 .setDone(true) 1204 .setResponse(Any.pack(expectedResponse)) 1205 .build(); 1206 mockService.addResponse(resultOperation); 1207 1208 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1209 List<EntityType.Entity> entities = new ArrayList<>(); 1210 String languageCode = "languageCode-2092349083"; 1211 1212 client.batchCreateEntitiesAsync(parent, entities, languageCode).get(); 1213 1214 List<String> actualRequests = mockService.getRequestPaths(); 1215 Assert.assertEquals(1, actualRequests.size()); 1216 1217 String apiClientHeaderKey = 1218 mockService 1219 .getRequestHeaders() 1220 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1221 .iterator() 1222 .next(); 1223 Assert.assertTrue( 1224 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1225 .matcher(apiClientHeaderKey) 1226 .matches()); 1227 } 1228 1229 @Test batchCreateEntitiesExceptionTest4()1230 public void batchCreateEntitiesExceptionTest4() throws Exception { 1231 ApiException exception = 1232 ApiExceptionFactory.createException( 1233 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1234 mockService.addException(exception); 1235 1236 try { 1237 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1238 List<EntityType.Entity> entities = new ArrayList<>(); 1239 String languageCode = "languageCode-2092349083"; 1240 client.batchCreateEntitiesAsync(parent, entities, languageCode).get(); 1241 Assert.fail("No exception raised"); 1242 } catch (ExecutionException e) { 1243 } 1244 } 1245 1246 @Test batchUpdateEntitiesTest()1247 public void batchUpdateEntitiesTest() throws Exception { 1248 Empty expectedResponse = Empty.newBuilder().build(); 1249 Operation resultOperation = 1250 Operation.newBuilder() 1251 .setName("batchUpdateEntitiesTest") 1252 .setDone(true) 1253 .setResponse(Any.pack(expectedResponse)) 1254 .build(); 1255 mockService.addResponse(resultOperation); 1256 1257 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1258 List<EntityType.Entity> entities = new ArrayList<>(); 1259 1260 client.batchUpdateEntitiesAsync(parent, entities).get(); 1261 1262 List<String> actualRequests = mockService.getRequestPaths(); 1263 Assert.assertEquals(1, actualRequests.size()); 1264 1265 String apiClientHeaderKey = 1266 mockService 1267 .getRequestHeaders() 1268 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1269 .iterator() 1270 .next(); 1271 Assert.assertTrue( 1272 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1273 .matcher(apiClientHeaderKey) 1274 .matches()); 1275 } 1276 1277 @Test batchUpdateEntitiesExceptionTest()1278 public void batchUpdateEntitiesExceptionTest() throws Exception { 1279 ApiException exception = 1280 ApiExceptionFactory.createException( 1281 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1282 mockService.addException(exception); 1283 1284 try { 1285 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1286 List<EntityType.Entity> entities = new ArrayList<>(); 1287 client.batchUpdateEntitiesAsync(parent, entities).get(); 1288 Assert.fail("No exception raised"); 1289 } catch (ExecutionException e) { 1290 } 1291 } 1292 1293 @Test batchUpdateEntitiesTest2()1294 public void batchUpdateEntitiesTest2() throws Exception { 1295 Empty expectedResponse = Empty.newBuilder().build(); 1296 Operation resultOperation = 1297 Operation.newBuilder() 1298 .setName("batchUpdateEntitiesTest") 1299 .setDone(true) 1300 .setResponse(Any.pack(expectedResponse)) 1301 .build(); 1302 mockService.addResponse(resultOperation); 1303 1304 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1305 List<EntityType.Entity> entities = new ArrayList<>(); 1306 1307 client.batchUpdateEntitiesAsync(parent, entities).get(); 1308 1309 List<String> actualRequests = mockService.getRequestPaths(); 1310 Assert.assertEquals(1, actualRequests.size()); 1311 1312 String apiClientHeaderKey = 1313 mockService 1314 .getRequestHeaders() 1315 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1316 .iterator() 1317 .next(); 1318 Assert.assertTrue( 1319 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1320 .matcher(apiClientHeaderKey) 1321 .matches()); 1322 } 1323 1324 @Test batchUpdateEntitiesExceptionTest2()1325 public void batchUpdateEntitiesExceptionTest2() throws Exception { 1326 ApiException exception = 1327 ApiExceptionFactory.createException( 1328 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1329 mockService.addException(exception); 1330 1331 try { 1332 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1333 List<EntityType.Entity> entities = new ArrayList<>(); 1334 client.batchUpdateEntitiesAsync(parent, entities).get(); 1335 Assert.fail("No exception raised"); 1336 } catch (ExecutionException e) { 1337 } 1338 } 1339 1340 @Test batchUpdateEntitiesTest3()1341 public void batchUpdateEntitiesTest3() throws Exception { 1342 Empty expectedResponse = Empty.newBuilder().build(); 1343 Operation resultOperation = 1344 Operation.newBuilder() 1345 .setName("batchUpdateEntitiesTest") 1346 .setDone(true) 1347 .setResponse(Any.pack(expectedResponse)) 1348 .build(); 1349 mockService.addResponse(resultOperation); 1350 1351 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1352 List<EntityType.Entity> entities = new ArrayList<>(); 1353 String languageCode = "languageCode-2092349083"; 1354 1355 client.batchUpdateEntitiesAsync(parent, entities, languageCode).get(); 1356 1357 List<String> actualRequests = mockService.getRequestPaths(); 1358 Assert.assertEquals(1, actualRequests.size()); 1359 1360 String apiClientHeaderKey = 1361 mockService 1362 .getRequestHeaders() 1363 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1364 .iterator() 1365 .next(); 1366 Assert.assertTrue( 1367 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1368 .matcher(apiClientHeaderKey) 1369 .matches()); 1370 } 1371 1372 @Test batchUpdateEntitiesExceptionTest3()1373 public void batchUpdateEntitiesExceptionTest3() throws Exception { 1374 ApiException exception = 1375 ApiExceptionFactory.createException( 1376 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1377 mockService.addException(exception); 1378 1379 try { 1380 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1381 List<EntityType.Entity> entities = new ArrayList<>(); 1382 String languageCode = "languageCode-2092349083"; 1383 client.batchUpdateEntitiesAsync(parent, entities, languageCode).get(); 1384 Assert.fail("No exception raised"); 1385 } catch (ExecutionException e) { 1386 } 1387 } 1388 1389 @Test batchUpdateEntitiesTest4()1390 public void batchUpdateEntitiesTest4() throws Exception { 1391 Empty expectedResponse = Empty.newBuilder().build(); 1392 Operation resultOperation = 1393 Operation.newBuilder() 1394 .setName("batchUpdateEntitiesTest") 1395 .setDone(true) 1396 .setResponse(Any.pack(expectedResponse)) 1397 .build(); 1398 mockService.addResponse(resultOperation); 1399 1400 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1401 List<EntityType.Entity> entities = new ArrayList<>(); 1402 String languageCode = "languageCode-2092349083"; 1403 1404 client.batchUpdateEntitiesAsync(parent, entities, languageCode).get(); 1405 1406 List<String> actualRequests = mockService.getRequestPaths(); 1407 Assert.assertEquals(1, actualRequests.size()); 1408 1409 String apiClientHeaderKey = 1410 mockService 1411 .getRequestHeaders() 1412 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1413 .iterator() 1414 .next(); 1415 Assert.assertTrue( 1416 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1417 .matcher(apiClientHeaderKey) 1418 .matches()); 1419 } 1420 1421 @Test batchUpdateEntitiesExceptionTest4()1422 public void batchUpdateEntitiesExceptionTest4() throws Exception { 1423 ApiException exception = 1424 ApiExceptionFactory.createException( 1425 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1426 mockService.addException(exception); 1427 1428 try { 1429 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1430 List<EntityType.Entity> entities = new ArrayList<>(); 1431 String languageCode = "languageCode-2092349083"; 1432 client.batchUpdateEntitiesAsync(parent, entities, languageCode).get(); 1433 Assert.fail("No exception raised"); 1434 } catch (ExecutionException e) { 1435 } 1436 } 1437 1438 @Test batchDeleteEntitiesTest()1439 public void batchDeleteEntitiesTest() throws Exception { 1440 Empty expectedResponse = Empty.newBuilder().build(); 1441 Operation resultOperation = 1442 Operation.newBuilder() 1443 .setName("batchDeleteEntitiesTest") 1444 .setDone(true) 1445 .setResponse(Any.pack(expectedResponse)) 1446 .build(); 1447 mockService.addResponse(resultOperation); 1448 1449 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1450 List<String> entityValues = new ArrayList<>(); 1451 1452 client.batchDeleteEntitiesAsync(parent, entityValues).get(); 1453 1454 List<String> actualRequests = mockService.getRequestPaths(); 1455 Assert.assertEquals(1, actualRequests.size()); 1456 1457 String apiClientHeaderKey = 1458 mockService 1459 .getRequestHeaders() 1460 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1461 .iterator() 1462 .next(); 1463 Assert.assertTrue( 1464 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1465 .matcher(apiClientHeaderKey) 1466 .matches()); 1467 } 1468 1469 @Test batchDeleteEntitiesExceptionTest()1470 public void batchDeleteEntitiesExceptionTest() throws Exception { 1471 ApiException exception = 1472 ApiExceptionFactory.createException( 1473 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1474 mockService.addException(exception); 1475 1476 try { 1477 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1478 List<String> entityValues = new ArrayList<>(); 1479 client.batchDeleteEntitiesAsync(parent, entityValues).get(); 1480 Assert.fail("No exception raised"); 1481 } catch (ExecutionException e) { 1482 } 1483 } 1484 1485 @Test batchDeleteEntitiesTest2()1486 public void batchDeleteEntitiesTest2() throws Exception { 1487 Empty expectedResponse = Empty.newBuilder().build(); 1488 Operation resultOperation = 1489 Operation.newBuilder() 1490 .setName("batchDeleteEntitiesTest") 1491 .setDone(true) 1492 .setResponse(Any.pack(expectedResponse)) 1493 .build(); 1494 mockService.addResponse(resultOperation); 1495 1496 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1497 List<String> entityValues = new ArrayList<>(); 1498 1499 client.batchDeleteEntitiesAsync(parent, entityValues).get(); 1500 1501 List<String> actualRequests = mockService.getRequestPaths(); 1502 Assert.assertEquals(1, actualRequests.size()); 1503 1504 String apiClientHeaderKey = 1505 mockService 1506 .getRequestHeaders() 1507 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1508 .iterator() 1509 .next(); 1510 Assert.assertTrue( 1511 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1512 .matcher(apiClientHeaderKey) 1513 .matches()); 1514 } 1515 1516 @Test batchDeleteEntitiesExceptionTest2()1517 public void batchDeleteEntitiesExceptionTest2() throws Exception { 1518 ApiException exception = 1519 ApiExceptionFactory.createException( 1520 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1521 mockService.addException(exception); 1522 1523 try { 1524 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1525 List<String> entityValues = new ArrayList<>(); 1526 client.batchDeleteEntitiesAsync(parent, entityValues).get(); 1527 Assert.fail("No exception raised"); 1528 } catch (ExecutionException e) { 1529 } 1530 } 1531 1532 @Test batchDeleteEntitiesTest3()1533 public void batchDeleteEntitiesTest3() throws Exception { 1534 Empty expectedResponse = Empty.newBuilder().build(); 1535 Operation resultOperation = 1536 Operation.newBuilder() 1537 .setName("batchDeleteEntitiesTest") 1538 .setDone(true) 1539 .setResponse(Any.pack(expectedResponse)) 1540 .build(); 1541 mockService.addResponse(resultOperation); 1542 1543 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1544 List<String> entityValues = new ArrayList<>(); 1545 String languageCode = "languageCode-2092349083"; 1546 1547 client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get(); 1548 1549 List<String> actualRequests = mockService.getRequestPaths(); 1550 Assert.assertEquals(1, actualRequests.size()); 1551 1552 String apiClientHeaderKey = 1553 mockService 1554 .getRequestHeaders() 1555 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1556 .iterator() 1557 .next(); 1558 Assert.assertTrue( 1559 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1560 .matcher(apiClientHeaderKey) 1561 .matches()); 1562 } 1563 1564 @Test batchDeleteEntitiesExceptionTest3()1565 public void batchDeleteEntitiesExceptionTest3() throws Exception { 1566 ApiException exception = 1567 ApiExceptionFactory.createException( 1568 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1569 mockService.addException(exception); 1570 1571 try { 1572 EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]"); 1573 List<String> entityValues = new ArrayList<>(); 1574 String languageCode = "languageCode-2092349083"; 1575 client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get(); 1576 Assert.fail("No exception raised"); 1577 } catch (ExecutionException e) { 1578 } 1579 } 1580 1581 @Test batchDeleteEntitiesTest4()1582 public void batchDeleteEntitiesTest4() throws Exception { 1583 Empty expectedResponse = Empty.newBuilder().build(); 1584 Operation resultOperation = 1585 Operation.newBuilder() 1586 .setName("batchDeleteEntitiesTest") 1587 .setDone(true) 1588 .setResponse(Any.pack(expectedResponse)) 1589 .build(); 1590 mockService.addResponse(resultOperation); 1591 1592 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1593 List<String> entityValues = new ArrayList<>(); 1594 String languageCode = "languageCode-2092349083"; 1595 1596 client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get(); 1597 1598 List<String> actualRequests = mockService.getRequestPaths(); 1599 Assert.assertEquals(1, actualRequests.size()); 1600 1601 String apiClientHeaderKey = 1602 mockService 1603 .getRequestHeaders() 1604 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1605 .iterator() 1606 .next(); 1607 Assert.assertTrue( 1608 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1609 .matcher(apiClientHeaderKey) 1610 .matches()); 1611 } 1612 1613 @Test batchDeleteEntitiesExceptionTest4()1614 public void batchDeleteEntitiesExceptionTest4() throws Exception { 1615 ApiException exception = 1616 ApiExceptionFactory.createException( 1617 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1618 mockService.addException(exception); 1619 1620 try { 1621 String parent = "projects/project-2105/agent/entityTypes/entityType-2105"; 1622 List<String> entityValues = new ArrayList<>(); 1623 String languageCode = "languageCode-2092349083"; 1624 client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get(); 1625 Assert.fail("No exception raised"); 1626 } catch (ExecutionException e) { 1627 } 1628 } 1629 1630 @Test listLocationsTest()1631 public void listLocationsTest() throws Exception { 1632 Location responsesElement = Location.newBuilder().build(); 1633 ListLocationsResponse expectedResponse = 1634 ListLocationsResponse.newBuilder() 1635 .setNextPageToken("") 1636 .addAllLocations(Arrays.asList(responsesElement)) 1637 .build(); 1638 mockService.addResponse(expectedResponse); 1639 1640 ListLocationsRequest request = 1641 ListLocationsRequest.newBuilder() 1642 .setName("projects/project-3664") 1643 .setFilter("filter-1274492040") 1644 .setPageSize(883849137) 1645 .setPageToken("pageToken873572522") 1646 .build(); 1647 1648 ListLocationsPagedResponse pagedListResponse = client.listLocations(request); 1649 1650 List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1651 1652 Assert.assertEquals(1, resources.size()); 1653 Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0)); 1654 1655 List<String> actualRequests = mockService.getRequestPaths(); 1656 Assert.assertEquals(1, actualRequests.size()); 1657 1658 String apiClientHeaderKey = 1659 mockService 1660 .getRequestHeaders() 1661 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1662 .iterator() 1663 .next(); 1664 Assert.assertTrue( 1665 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1666 .matcher(apiClientHeaderKey) 1667 .matches()); 1668 } 1669 1670 @Test listLocationsExceptionTest()1671 public void listLocationsExceptionTest() throws Exception { 1672 ApiException exception = 1673 ApiExceptionFactory.createException( 1674 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1675 mockService.addException(exception); 1676 1677 try { 1678 ListLocationsRequest request = 1679 ListLocationsRequest.newBuilder() 1680 .setName("projects/project-3664") 1681 .setFilter("filter-1274492040") 1682 .setPageSize(883849137) 1683 .setPageToken("pageToken873572522") 1684 .build(); 1685 client.listLocations(request); 1686 Assert.fail("No exception raised"); 1687 } catch (InvalidArgumentException e) { 1688 // Expected exception. 1689 } 1690 } 1691 1692 @Test getLocationTest()1693 public void getLocationTest() throws Exception { 1694 Location expectedResponse = 1695 Location.newBuilder() 1696 .setName("name3373707") 1697 .setLocationId("locationId1541836720") 1698 .setDisplayName("displayName1714148973") 1699 .putAllLabels(new HashMap<String, String>()) 1700 .setMetadata(Any.newBuilder().build()) 1701 .build(); 1702 mockService.addResponse(expectedResponse); 1703 1704 GetLocationRequest request = 1705 GetLocationRequest.newBuilder() 1706 .setName("projects/project-9062/locations/location-9062") 1707 .build(); 1708 1709 Location actualResponse = client.getLocation(request); 1710 Assert.assertEquals(expectedResponse, actualResponse); 1711 1712 List<String> actualRequests = mockService.getRequestPaths(); 1713 Assert.assertEquals(1, actualRequests.size()); 1714 1715 String apiClientHeaderKey = 1716 mockService 1717 .getRequestHeaders() 1718 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1719 .iterator() 1720 .next(); 1721 Assert.assertTrue( 1722 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1723 .matcher(apiClientHeaderKey) 1724 .matches()); 1725 } 1726 1727 @Test getLocationExceptionTest()1728 public void getLocationExceptionTest() throws Exception { 1729 ApiException exception = 1730 ApiExceptionFactory.createException( 1731 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1732 mockService.addException(exception); 1733 1734 try { 1735 GetLocationRequest request = 1736 GetLocationRequest.newBuilder() 1737 .setName("projects/project-9062/locations/location-9062") 1738 .build(); 1739 client.getLocation(request); 1740 Assert.fail("No exception raised"); 1741 } catch (InvalidArgumentException e) { 1742 // Expected exception. 1743 } 1744 } 1745 } 1746