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.IntentsClient.ListIntentsPagedResponse; 20 import static com.google.cloud.dialogflow.v2.IntentsClient.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.HttpJsonIntentsStub; 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 IntentsClientHttpJsonTest { 57 private static MockHttpService mockService; 58 private static IntentsClient client; 59 60 @BeforeClass startStaticServer()61 public static void startStaticServer() throws IOException { 62 mockService = 63 new MockHttpService( 64 HttpJsonIntentsStub.getMethodDescriptors(), IntentsSettings.getDefaultEndpoint()); 65 IntentsSettings settings = 66 IntentsSettings.newHttpJsonBuilder() 67 .setTransportChannelProvider( 68 IntentsSettings.defaultHttpJsonTransportProviderBuilder() 69 .setHttpTransport(mockService) 70 .build()) 71 .setCredentialsProvider(NoCredentialsProvider.create()) 72 .build(); 73 client = IntentsClient.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 listIntentsTest()90 public void listIntentsTest() throws Exception { 91 Intent responsesElement = Intent.newBuilder().build(); 92 ListIntentsResponse expectedResponse = 93 ListIntentsResponse.newBuilder() 94 .setNextPageToken("") 95 .addAllIntents(Arrays.asList(responsesElement)) 96 .build(); 97 mockService.addResponse(expectedResponse); 98 99 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 100 101 ListIntentsPagedResponse pagedListResponse = client.listIntents(parent); 102 103 List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 104 105 Assert.assertEquals(1, resources.size()); 106 Assert.assertEquals(expectedResponse.getIntentsList().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 listIntentsExceptionTest()124 public void listIntentsExceptionTest() 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 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 132 client.listIntents(parent); 133 Assert.fail("No exception raised"); 134 } catch (InvalidArgumentException e) { 135 // Expected exception. 136 } 137 } 138 139 @Test listIntentsTest2()140 public void listIntentsTest2() throws Exception { 141 Intent responsesElement = Intent.newBuilder().build(); 142 ListIntentsResponse expectedResponse = 143 ListIntentsResponse.newBuilder() 144 .setNextPageToken("") 145 .addAllIntents(Arrays.asList(responsesElement)) 146 .build(); 147 mockService.addResponse(expectedResponse); 148 149 String parent = "projects/project-2469/agent"; 150 151 ListIntentsPagedResponse pagedListResponse = client.listIntents(parent); 152 153 List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 154 155 Assert.assertEquals(1, resources.size()); 156 Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0)); 157 158 List<String> actualRequests = mockService.getRequestPaths(); 159 Assert.assertEquals(1, actualRequests.size()); 160 161 String apiClientHeaderKey = 162 mockService 163 .getRequestHeaders() 164 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 165 .iterator() 166 .next(); 167 Assert.assertTrue( 168 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 169 .matcher(apiClientHeaderKey) 170 .matches()); 171 } 172 173 @Test listIntentsExceptionTest2()174 public void listIntentsExceptionTest2() throws Exception { 175 ApiException exception = 176 ApiExceptionFactory.createException( 177 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 178 mockService.addException(exception); 179 180 try { 181 String parent = "projects/project-2469/agent"; 182 client.listIntents(parent); 183 Assert.fail("No exception raised"); 184 } catch (InvalidArgumentException e) { 185 // Expected exception. 186 } 187 } 188 189 @Test listIntentsTest3()190 public void listIntentsTest3() throws Exception { 191 Intent responsesElement = Intent.newBuilder().build(); 192 ListIntentsResponse expectedResponse = 193 ListIntentsResponse.newBuilder() 194 .setNextPageToken("") 195 .addAllIntents(Arrays.asList(responsesElement)) 196 .build(); 197 mockService.addResponse(expectedResponse); 198 199 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 200 String languageCode = "languageCode-2092349083"; 201 202 ListIntentsPagedResponse pagedListResponse = client.listIntents(parent, languageCode); 203 204 List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 205 206 Assert.assertEquals(1, resources.size()); 207 Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0)); 208 209 List<String> actualRequests = mockService.getRequestPaths(); 210 Assert.assertEquals(1, actualRequests.size()); 211 212 String apiClientHeaderKey = 213 mockService 214 .getRequestHeaders() 215 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 216 .iterator() 217 .next(); 218 Assert.assertTrue( 219 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 220 .matcher(apiClientHeaderKey) 221 .matches()); 222 } 223 224 @Test listIntentsExceptionTest3()225 public void listIntentsExceptionTest3() throws Exception { 226 ApiException exception = 227 ApiExceptionFactory.createException( 228 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 229 mockService.addException(exception); 230 231 try { 232 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 233 String languageCode = "languageCode-2092349083"; 234 client.listIntents(parent, languageCode); 235 Assert.fail("No exception raised"); 236 } catch (InvalidArgumentException e) { 237 // Expected exception. 238 } 239 } 240 241 @Test listIntentsTest4()242 public void listIntentsTest4() throws Exception { 243 Intent responsesElement = Intent.newBuilder().build(); 244 ListIntentsResponse expectedResponse = 245 ListIntentsResponse.newBuilder() 246 .setNextPageToken("") 247 .addAllIntents(Arrays.asList(responsesElement)) 248 .build(); 249 mockService.addResponse(expectedResponse); 250 251 String parent = "projects/project-2469/agent"; 252 String languageCode = "languageCode-2092349083"; 253 254 ListIntentsPagedResponse pagedListResponse = client.listIntents(parent, languageCode); 255 256 List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 257 258 Assert.assertEquals(1, resources.size()); 259 Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0)); 260 261 List<String> actualRequests = mockService.getRequestPaths(); 262 Assert.assertEquals(1, actualRequests.size()); 263 264 String apiClientHeaderKey = 265 mockService 266 .getRequestHeaders() 267 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 268 .iterator() 269 .next(); 270 Assert.assertTrue( 271 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 272 .matcher(apiClientHeaderKey) 273 .matches()); 274 } 275 276 @Test listIntentsExceptionTest4()277 public void listIntentsExceptionTest4() throws Exception { 278 ApiException exception = 279 ApiExceptionFactory.createException( 280 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 281 mockService.addException(exception); 282 283 try { 284 String parent = "projects/project-2469/agent"; 285 String languageCode = "languageCode-2092349083"; 286 client.listIntents(parent, languageCode); 287 Assert.fail("No exception raised"); 288 } catch (InvalidArgumentException e) { 289 // Expected exception. 290 } 291 } 292 293 @Test getIntentTest()294 public void getIntentTest() throws Exception { 295 Intent expectedResponse = 296 Intent.newBuilder() 297 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 298 .setDisplayName("displayName1714148973") 299 .setPriority(-1165461084) 300 .setIsFallback(true) 301 .setMlDisabled(true) 302 .setLiveAgentHandoff(true) 303 .setEndInteraction(true) 304 .addAllInputContextNames(new ArrayList<String>()) 305 .addAllEvents(new ArrayList<String>()) 306 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 307 .setAction("action-1422950858") 308 .addAllOutputContexts(new ArrayList<Context>()) 309 .setResetContexts(true) 310 .addAllParameters(new ArrayList<Intent.Parameter>()) 311 .addAllMessages(new ArrayList<Intent.Message>()) 312 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 313 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 314 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 315 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 316 .build(); 317 mockService.addResponse(expectedResponse); 318 319 IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]"); 320 321 Intent actualResponse = client.getIntent(name); 322 Assert.assertEquals(expectedResponse, actualResponse); 323 324 List<String> actualRequests = mockService.getRequestPaths(); 325 Assert.assertEquals(1, actualRequests.size()); 326 327 String apiClientHeaderKey = 328 mockService 329 .getRequestHeaders() 330 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 331 .iterator() 332 .next(); 333 Assert.assertTrue( 334 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 335 .matcher(apiClientHeaderKey) 336 .matches()); 337 } 338 339 @Test getIntentExceptionTest()340 public void getIntentExceptionTest() throws Exception { 341 ApiException exception = 342 ApiExceptionFactory.createException( 343 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 344 mockService.addException(exception); 345 346 try { 347 IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]"); 348 client.getIntent(name); 349 Assert.fail("No exception raised"); 350 } catch (InvalidArgumentException e) { 351 // Expected exception. 352 } 353 } 354 355 @Test getIntentTest2()356 public void getIntentTest2() throws Exception { 357 Intent expectedResponse = 358 Intent.newBuilder() 359 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 360 .setDisplayName("displayName1714148973") 361 .setPriority(-1165461084) 362 .setIsFallback(true) 363 .setMlDisabled(true) 364 .setLiveAgentHandoff(true) 365 .setEndInteraction(true) 366 .addAllInputContextNames(new ArrayList<String>()) 367 .addAllEvents(new ArrayList<String>()) 368 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 369 .setAction("action-1422950858") 370 .addAllOutputContexts(new ArrayList<Context>()) 371 .setResetContexts(true) 372 .addAllParameters(new ArrayList<Intent.Parameter>()) 373 .addAllMessages(new ArrayList<Intent.Message>()) 374 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 375 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 376 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 377 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 378 .build(); 379 mockService.addResponse(expectedResponse); 380 381 String name = "projects/project-1783/agent/intents/intent-1783"; 382 383 Intent actualResponse = client.getIntent(name); 384 Assert.assertEquals(expectedResponse, actualResponse); 385 386 List<String> actualRequests = mockService.getRequestPaths(); 387 Assert.assertEquals(1, actualRequests.size()); 388 389 String apiClientHeaderKey = 390 mockService 391 .getRequestHeaders() 392 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 393 .iterator() 394 .next(); 395 Assert.assertTrue( 396 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 397 .matcher(apiClientHeaderKey) 398 .matches()); 399 } 400 401 @Test getIntentExceptionTest2()402 public void getIntentExceptionTest2() throws Exception { 403 ApiException exception = 404 ApiExceptionFactory.createException( 405 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 406 mockService.addException(exception); 407 408 try { 409 String name = "projects/project-1783/agent/intents/intent-1783"; 410 client.getIntent(name); 411 Assert.fail("No exception raised"); 412 } catch (InvalidArgumentException e) { 413 // Expected exception. 414 } 415 } 416 417 @Test getIntentTest3()418 public void getIntentTest3() throws Exception { 419 Intent expectedResponse = 420 Intent.newBuilder() 421 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 422 .setDisplayName("displayName1714148973") 423 .setPriority(-1165461084) 424 .setIsFallback(true) 425 .setMlDisabled(true) 426 .setLiveAgentHandoff(true) 427 .setEndInteraction(true) 428 .addAllInputContextNames(new ArrayList<String>()) 429 .addAllEvents(new ArrayList<String>()) 430 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 431 .setAction("action-1422950858") 432 .addAllOutputContexts(new ArrayList<Context>()) 433 .setResetContexts(true) 434 .addAllParameters(new ArrayList<Intent.Parameter>()) 435 .addAllMessages(new ArrayList<Intent.Message>()) 436 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 437 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 438 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 439 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 440 .build(); 441 mockService.addResponse(expectedResponse); 442 443 IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]"); 444 String languageCode = "languageCode-2092349083"; 445 446 Intent actualResponse = client.getIntent(name, languageCode); 447 Assert.assertEquals(expectedResponse, actualResponse); 448 449 List<String> actualRequests = mockService.getRequestPaths(); 450 Assert.assertEquals(1, actualRequests.size()); 451 452 String apiClientHeaderKey = 453 mockService 454 .getRequestHeaders() 455 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 456 .iterator() 457 .next(); 458 Assert.assertTrue( 459 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 460 .matcher(apiClientHeaderKey) 461 .matches()); 462 } 463 464 @Test getIntentExceptionTest3()465 public void getIntentExceptionTest3() throws Exception { 466 ApiException exception = 467 ApiExceptionFactory.createException( 468 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 469 mockService.addException(exception); 470 471 try { 472 IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]"); 473 String languageCode = "languageCode-2092349083"; 474 client.getIntent(name, languageCode); 475 Assert.fail("No exception raised"); 476 } catch (InvalidArgumentException e) { 477 // Expected exception. 478 } 479 } 480 481 @Test getIntentTest4()482 public void getIntentTest4() throws Exception { 483 Intent expectedResponse = 484 Intent.newBuilder() 485 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 486 .setDisplayName("displayName1714148973") 487 .setPriority(-1165461084) 488 .setIsFallback(true) 489 .setMlDisabled(true) 490 .setLiveAgentHandoff(true) 491 .setEndInteraction(true) 492 .addAllInputContextNames(new ArrayList<String>()) 493 .addAllEvents(new ArrayList<String>()) 494 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 495 .setAction("action-1422950858") 496 .addAllOutputContexts(new ArrayList<Context>()) 497 .setResetContexts(true) 498 .addAllParameters(new ArrayList<Intent.Parameter>()) 499 .addAllMessages(new ArrayList<Intent.Message>()) 500 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 501 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 502 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 503 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 504 .build(); 505 mockService.addResponse(expectedResponse); 506 507 String name = "projects/project-1783/agent/intents/intent-1783"; 508 String languageCode = "languageCode-2092349083"; 509 510 Intent actualResponse = client.getIntent(name, languageCode); 511 Assert.assertEquals(expectedResponse, actualResponse); 512 513 List<String> actualRequests = mockService.getRequestPaths(); 514 Assert.assertEquals(1, actualRequests.size()); 515 516 String apiClientHeaderKey = 517 mockService 518 .getRequestHeaders() 519 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 520 .iterator() 521 .next(); 522 Assert.assertTrue( 523 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 524 .matcher(apiClientHeaderKey) 525 .matches()); 526 } 527 528 @Test getIntentExceptionTest4()529 public void getIntentExceptionTest4() throws Exception { 530 ApiException exception = 531 ApiExceptionFactory.createException( 532 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 533 mockService.addException(exception); 534 535 try { 536 String name = "projects/project-1783/agent/intents/intent-1783"; 537 String languageCode = "languageCode-2092349083"; 538 client.getIntent(name, languageCode); 539 Assert.fail("No exception raised"); 540 } catch (InvalidArgumentException e) { 541 // Expected exception. 542 } 543 } 544 545 @Test createIntentTest()546 public void createIntentTest() throws Exception { 547 Intent expectedResponse = 548 Intent.newBuilder() 549 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 550 .setDisplayName("displayName1714148973") 551 .setPriority(-1165461084) 552 .setIsFallback(true) 553 .setMlDisabled(true) 554 .setLiveAgentHandoff(true) 555 .setEndInteraction(true) 556 .addAllInputContextNames(new ArrayList<String>()) 557 .addAllEvents(new ArrayList<String>()) 558 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 559 .setAction("action-1422950858") 560 .addAllOutputContexts(new ArrayList<Context>()) 561 .setResetContexts(true) 562 .addAllParameters(new ArrayList<Intent.Parameter>()) 563 .addAllMessages(new ArrayList<Intent.Message>()) 564 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 565 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 566 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 567 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 568 .build(); 569 mockService.addResponse(expectedResponse); 570 571 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 572 Intent intent = Intent.newBuilder().build(); 573 574 Intent actualResponse = client.createIntent(parent, intent); 575 Assert.assertEquals(expectedResponse, actualResponse); 576 577 List<String> actualRequests = mockService.getRequestPaths(); 578 Assert.assertEquals(1, actualRequests.size()); 579 580 String apiClientHeaderKey = 581 mockService 582 .getRequestHeaders() 583 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 584 .iterator() 585 .next(); 586 Assert.assertTrue( 587 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 588 .matcher(apiClientHeaderKey) 589 .matches()); 590 } 591 592 @Test createIntentExceptionTest()593 public void createIntentExceptionTest() throws Exception { 594 ApiException exception = 595 ApiExceptionFactory.createException( 596 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 597 mockService.addException(exception); 598 599 try { 600 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 601 Intent intent = Intent.newBuilder().build(); 602 client.createIntent(parent, intent); 603 Assert.fail("No exception raised"); 604 } catch (InvalidArgumentException e) { 605 // Expected exception. 606 } 607 } 608 609 @Test createIntentTest2()610 public void createIntentTest2() throws Exception { 611 Intent expectedResponse = 612 Intent.newBuilder() 613 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 614 .setDisplayName("displayName1714148973") 615 .setPriority(-1165461084) 616 .setIsFallback(true) 617 .setMlDisabled(true) 618 .setLiveAgentHandoff(true) 619 .setEndInteraction(true) 620 .addAllInputContextNames(new ArrayList<String>()) 621 .addAllEvents(new ArrayList<String>()) 622 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 623 .setAction("action-1422950858") 624 .addAllOutputContexts(new ArrayList<Context>()) 625 .setResetContexts(true) 626 .addAllParameters(new ArrayList<Intent.Parameter>()) 627 .addAllMessages(new ArrayList<Intent.Message>()) 628 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 629 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 630 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 631 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 632 .build(); 633 mockService.addResponse(expectedResponse); 634 635 String parent = "projects/project-2469/agent"; 636 Intent intent = Intent.newBuilder().build(); 637 638 Intent actualResponse = client.createIntent(parent, intent); 639 Assert.assertEquals(expectedResponse, actualResponse); 640 641 List<String> actualRequests = mockService.getRequestPaths(); 642 Assert.assertEquals(1, actualRequests.size()); 643 644 String apiClientHeaderKey = 645 mockService 646 .getRequestHeaders() 647 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 648 .iterator() 649 .next(); 650 Assert.assertTrue( 651 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 652 .matcher(apiClientHeaderKey) 653 .matches()); 654 } 655 656 @Test createIntentExceptionTest2()657 public void createIntentExceptionTest2() throws Exception { 658 ApiException exception = 659 ApiExceptionFactory.createException( 660 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 661 mockService.addException(exception); 662 663 try { 664 String parent = "projects/project-2469/agent"; 665 Intent intent = Intent.newBuilder().build(); 666 client.createIntent(parent, intent); 667 Assert.fail("No exception raised"); 668 } catch (InvalidArgumentException e) { 669 // Expected exception. 670 } 671 } 672 673 @Test createIntentTest3()674 public void createIntentTest3() throws Exception { 675 Intent expectedResponse = 676 Intent.newBuilder() 677 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 678 .setDisplayName("displayName1714148973") 679 .setPriority(-1165461084) 680 .setIsFallback(true) 681 .setMlDisabled(true) 682 .setLiveAgentHandoff(true) 683 .setEndInteraction(true) 684 .addAllInputContextNames(new ArrayList<String>()) 685 .addAllEvents(new ArrayList<String>()) 686 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 687 .setAction("action-1422950858") 688 .addAllOutputContexts(new ArrayList<Context>()) 689 .setResetContexts(true) 690 .addAllParameters(new ArrayList<Intent.Parameter>()) 691 .addAllMessages(new ArrayList<Intent.Message>()) 692 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 693 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 694 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 695 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 696 .build(); 697 mockService.addResponse(expectedResponse); 698 699 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 700 Intent intent = Intent.newBuilder().build(); 701 String languageCode = "languageCode-2092349083"; 702 703 Intent actualResponse = client.createIntent(parent, intent, languageCode); 704 Assert.assertEquals(expectedResponse, actualResponse); 705 706 List<String> actualRequests = mockService.getRequestPaths(); 707 Assert.assertEquals(1, actualRequests.size()); 708 709 String apiClientHeaderKey = 710 mockService 711 .getRequestHeaders() 712 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 713 .iterator() 714 .next(); 715 Assert.assertTrue( 716 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 717 .matcher(apiClientHeaderKey) 718 .matches()); 719 } 720 721 @Test createIntentExceptionTest3()722 public void createIntentExceptionTest3() throws Exception { 723 ApiException exception = 724 ApiExceptionFactory.createException( 725 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 726 mockService.addException(exception); 727 728 try { 729 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 730 Intent intent = Intent.newBuilder().build(); 731 String languageCode = "languageCode-2092349083"; 732 client.createIntent(parent, intent, languageCode); 733 Assert.fail("No exception raised"); 734 } catch (InvalidArgumentException e) { 735 // Expected exception. 736 } 737 } 738 739 @Test createIntentTest4()740 public void createIntentTest4() throws Exception { 741 Intent expectedResponse = 742 Intent.newBuilder() 743 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 744 .setDisplayName("displayName1714148973") 745 .setPriority(-1165461084) 746 .setIsFallback(true) 747 .setMlDisabled(true) 748 .setLiveAgentHandoff(true) 749 .setEndInteraction(true) 750 .addAllInputContextNames(new ArrayList<String>()) 751 .addAllEvents(new ArrayList<String>()) 752 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 753 .setAction("action-1422950858") 754 .addAllOutputContexts(new ArrayList<Context>()) 755 .setResetContexts(true) 756 .addAllParameters(new ArrayList<Intent.Parameter>()) 757 .addAllMessages(new ArrayList<Intent.Message>()) 758 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 759 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 760 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 761 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 762 .build(); 763 mockService.addResponse(expectedResponse); 764 765 String parent = "projects/project-2469/agent"; 766 Intent intent = Intent.newBuilder().build(); 767 String languageCode = "languageCode-2092349083"; 768 769 Intent actualResponse = client.createIntent(parent, intent, languageCode); 770 Assert.assertEquals(expectedResponse, actualResponse); 771 772 List<String> actualRequests = mockService.getRequestPaths(); 773 Assert.assertEquals(1, actualRequests.size()); 774 775 String apiClientHeaderKey = 776 mockService 777 .getRequestHeaders() 778 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 779 .iterator() 780 .next(); 781 Assert.assertTrue( 782 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 783 .matcher(apiClientHeaderKey) 784 .matches()); 785 } 786 787 @Test createIntentExceptionTest4()788 public void createIntentExceptionTest4() throws Exception { 789 ApiException exception = 790 ApiExceptionFactory.createException( 791 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 792 mockService.addException(exception); 793 794 try { 795 String parent = "projects/project-2469/agent"; 796 Intent intent = Intent.newBuilder().build(); 797 String languageCode = "languageCode-2092349083"; 798 client.createIntent(parent, intent, languageCode); 799 Assert.fail("No exception raised"); 800 } catch (InvalidArgumentException e) { 801 // Expected exception. 802 } 803 } 804 805 @Test updateIntentTest()806 public void updateIntentTest() throws Exception { 807 Intent expectedResponse = 808 Intent.newBuilder() 809 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 810 .setDisplayName("displayName1714148973") 811 .setPriority(-1165461084) 812 .setIsFallback(true) 813 .setMlDisabled(true) 814 .setLiveAgentHandoff(true) 815 .setEndInteraction(true) 816 .addAllInputContextNames(new ArrayList<String>()) 817 .addAllEvents(new ArrayList<String>()) 818 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 819 .setAction("action-1422950858") 820 .addAllOutputContexts(new ArrayList<Context>()) 821 .setResetContexts(true) 822 .addAllParameters(new ArrayList<Intent.Parameter>()) 823 .addAllMessages(new ArrayList<Intent.Message>()) 824 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 825 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 826 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 827 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 828 .build(); 829 mockService.addResponse(expectedResponse); 830 831 Intent intent = 832 Intent.newBuilder() 833 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 834 .setDisplayName("displayName1714148973") 835 .setPriority(-1165461084) 836 .setIsFallback(true) 837 .setMlDisabled(true) 838 .setLiveAgentHandoff(true) 839 .setEndInteraction(true) 840 .addAllInputContextNames(new ArrayList<String>()) 841 .addAllEvents(new ArrayList<String>()) 842 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 843 .setAction("action-1422950858") 844 .addAllOutputContexts(new ArrayList<Context>()) 845 .setResetContexts(true) 846 .addAllParameters(new ArrayList<Intent.Parameter>()) 847 .addAllMessages(new ArrayList<Intent.Message>()) 848 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 849 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 850 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 851 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 852 .build(); 853 String languageCode = "languageCode-2092349083"; 854 855 Intent actualResponse = client.updateIntent(intent, languageCode); 856 Assert.assertEquals(expectedResponse, actualResponse); 857 858 List<String> actualRequests = mockService.getRequestPaths(); 859 Assert.assertEquals(1, actualRequests.size()); 860 861 String apiClientHeaderKey = 862 mockService 863 .getRequestHeaders() 864 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 865 .iterator() 866 .next(); 867 Assert.assertTrue( 868 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 869 .matcher(apiClientHeaderKey) 870 .matches()); 871 } 872 873 @Test updateIntentExceptionTest()874 public void updateIntentExceptionTest() throws Exception { 875 ApiException exception = 876 ApiExceptionFactory.createException( 877 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 878 mockService.addException(exception); 879 880 try { 881 Intent intent = 882 Intent.newBuilder() 883 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 884 .setDisplayName("displayName1714148973") 885 .setPriority(-1165461084) 886 .setIsFallback(true) 887 .setMlDisabled(true) 888 .setLiveAgentHandoff(true) 889 .setEndInteraction(true) 890 .addAllInputContextNames(new ArrayList<String>()) 891 .addAllEvents(new ArrayList<String>()) 892 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 893 .setAction("action-1422950858") 894 .addAllOutputContexts(new ArrayList<Context>()) 895 .setResetContexts(true) 896 .addAllParameters(new ArrayList<Intent.Parameter>()) 897 .addAllMessages(new ArrayList<Intent.Message>()) 898 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 899 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 900 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 901 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 902 .build(); 903 String languageCode = "languageCode-2092349083"; 904 client.updateIntent(intent, languageCode); 905 Assert.fail("No exception raised"); 906 } catch (InvalidArgumentException e) { 907 // Expected exception. 908 } 909 } 910 911 @Test updateIntentTest2()912 public void updateIntentTest2() throws Exception { 913 Intent expectedResponse = 914 Intent.newBuilder() 915 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 916 .setDisplayName("displayName1714148973") 917 .setPriority(-1165461084) 918 .setIsFallback(true) 919 .setMlDisabled(true) 920 .setLiveAgentHandoff(true) 921 .setEndInteraction(true) 922 .addAllInputContextNames(new ArrayList<String>()) 923 .addAllEvents(new ArrayList<String>()) 924 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 925 .setAction("action-1422950858") 926 .addAllOutputContexts(new ArrayList<Context>()) 927 .setResetContexts(true) 928 .addAllParameters(new ArrayList<Intent.Parameter>()) 929 .addAllMessages(new ArrayList<Intent.Message>()) 930 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 931 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 932 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 933 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 934 .build(); 935 mockService.addResponse(expectedResponse); 936 937 Intent intent = 938 Intent.newBuilder() 939 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 940 .setDisplayName("displayName1714148973") 941 .setPriority(-1165461084) 942 .setIsFallback(true) 943 .setMlDisabled(true) 944 .setLiveAgentHandoff(true) 945 .setEndInteraction(true) 946 .addAllInputContextNames(new ArrayList<String>()) 947 .addAllEvents(new ArrayList<String>()) 948 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 949 .setAction("action-1422950858") 950 .addAllOutputContexts(new ArrayList<Context>()) 951 .setResetContexts(true) 952 .addAllParameters(new ArrayList<Intent.Parameter>()) 953 .addAllMessages(new ArrayList<Intent.Message>()) 954 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 955 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 956 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 957 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 958 .build(); 959 String languageCode = "languageCode-2092349083"; 960 FieldMask updateMask = FieldMask.newBuilder().build(); 961 962 Intent actualResponse = client.updateIntent(intent, languageCode, updateMask); 963 Assert.assertEquals(expectedResponse, actualResponse); 964 965 List<String> actualRequests = mockService.getRequestPaths(); 966 Assert.assertEquals(1, actualRequests.size()); 967 968 String apiClientHeaderKey = 969 mockService 970 .getRequestHeaders() 971 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 972 .iterator() 973 .next(); 974 Assert.assertTrue( 975 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 976 .matcher(apiClientHeaderKey) 977 .matches()); 978 } 979 980 @Test updateIntentExceptionTest2()981 public void updateIntentExceptionTest2() throws Exception { 982 ApiException exception = 983 ApiExceptionFactory.createException( 984 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 985 mockService.addException(exception); 986 987 try { 988 Intent intent = 989 Intent.newBuilder() 990 .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString()) 991 .setDisplayName("displayName1714148973") 992 .setPriority(-1165461084) 993 .setIsFallback(true) 994 .setMlDisabled(true) 995 .setLiveAgentHandoff(true) 996 .setEndInteraction(true) 997 .addAllInputContextNames(new ArrayList<String>()) 998 .addAllEvents(new ArrayList<String>()) 999 .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>()) 1000 .setAction("action-1422950858") 1001 .addAllOutputContexts(new ArrayList<Context>()) 1002 .setResetContexts(true) 1003 .addAllParameters(new ArrayList<Intent.Parameter>()) 1004 .addAllMessages(new ArrayList<Intent.Message>()) 1005 .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>()) 1006 .setRootFollowupIntentName("rootFollowupIntentName1370087157") 1007 .setParentFollowupIntentName("parentFollowupIntentName1233650877") 1008 .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>()) 1009 .build(); 1010 String languageCode = "languageCode-2092349083"; 1011 FieldMask updateMask = FieldMask.newBuilder().build(); 1012 client.updateIntent(intent, languageCode, updateMask); 1013 Assert.fail("No exception raised"); 1014 } catch (InvalidArgumentException e) { 1015 // Expected exception. 1016 } 1017 } 1018 1019 @Test deleteIntentTest()1020 public void deleteIntentTest() throws Exception { 1021 Empty expectedResponse = Empty.newBuilder().build(); 1022 mockService.addResponse(expectedResponse); 1023 1024 IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]"); 1025 1026 client.deleteIntent(name); 1027 1028 List<String> actualRequests = mockService.getRequestPaths(); 1029 Assert.assertEquals(1, actualRequests.size()); 1030 1031 String apiClientHeaderKey = 1032 mockService 1033 .getRequestHeaders() 1034 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1035 .iterator() 1036 .next(); 1037 Assert.assertTrue( 1038 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1039 .matcher(apiClientHeaderKey) 1040 .matches()); 1041 } 1042 1043 @Test deleteIntentExceptionTest()1044 public void deleteIntentExceptionTest() throws Exception { 1045 ApiException exception = 1046 ApiExceptionFactory.createException( 1047 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1048 mockService.addException(exception); 1049 1050 try { 1051 IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]"); 1052 client.deleteIntent(name); 1053 Assert.fail("No exception raised"); 1054 } catch (InvalidArgumentException e) { 1055 // Expected exception. 1056 } 1057 } 1058 1059 @Test deleteIntentTest2()1060 public void deleteIntentTest2() throws Exception { 1061 Empty expectedResponse = Empty.newBuilder().build(); 1062 mockService.addResponse(expectedResponse); 1063 1064 String name = "projects/project-1783/agent/intents/intent-1783"; 1065 1066 client.deleteIntent(name); 1067 1068 List<String> actualRequests = mockService.getRequestPaths(); 1069 Assert.assertEquals(1, actualRequests.size()); 1070 1071 String apiClientHeaderKey = 1072 mockService 1073 .getRequestHeaders() 1074 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1075 .iterator() 1076 .next(); 1077 Assert.assertTrue( 1078 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1079 .matcher(apiClientHeaderKey) 1080 .matches()); 1081 } 1082 1083 @Test deleteIntentExceptionTest2()1084 public void deleteIntentExceptionTest2() throws Exception { 1085 ApiException exception = 1086 ApiExceptionFactory.createException( 1087 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1088 mockService.addException(exception); 1089 1090 try { 1091 String name = "projects/project-1783/agent/intents/intent-1783"; 1092 client.deleteIntent(name); 1093 Assert.fail("No exception raised"); 1094 } catch (InvalidArgumentException e) { 1095 // Expected exception. 1096 } 1097 } 1098 1099 @Test batchUpdateIntentsTest()1100 public void batchUpdateIntentsTest() throws Exception { 1101 BatchUpdateIntentsResponse expectedResponse = 1102 BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build(); 1103 Operation resultOperation = 1104 Operation.newBuilder() 1105 .setName("batchUpdateIntentsTest") 1106 .setDone(true) 1107 .setResponse(Any.pack(expectedResponse)) 1108 .build(); 1109 mockService.addResponse(resultOperation); 1110 1111 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1112 IntentBatch intentBatchInline = IntentBatch.newBuilder().build(); 1113 1114 BatchUpdateIntentsResponse actualResponse = 1115 client.batchUpdateIntentsAsync(parent, intentBatchInline).get(); 1116 Assert.assertEquals(expectedResponse, actualResponse); 1117 1118 List<String> actualRequests = mockService.getRequestPaths(); 1119 Assert.assertEquals(1, actualRequests.size()); 1120 1121 String apiClientHeaderKey = 1122 mockService 1123 .getRequestHeaders() 1124 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1125 .iterator() 1126 .next(); 1127 Assert.assertTrue( 1128 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1129 .matcher(apiClientHeaderKey) 1130 .matches()); 1131 } 1132 1133 @Test batchUpdateIntentsExceptionTest()1134 public void batchUpdateIntentsExceptionTest() throws Exception { 1135 ApiException exception = 1136 ApiExceptionFactory.createException( 1137 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1138 mockService.addException(exception); 1139 1140 try { 1141 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1142 IntentBatch intentBatchInline = IntentBatch.newBuilder().build(); 1143 client.batchUpdateIntentsAsync(parent, intentBatchInline).get(); 1144 Assert.fail("No exception raised"); 1145 } catch (ExecutionException e) { 1146 } 1147 } 1148 1149 @Test batchUpdateIntentsTest2()1150 public void batchUpdateIntentsTest2() throws Exception { 1151 BatchUpdateIntentsResponse expectedResponse = 1152 BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build(); 1153 Operation resultOperation = 1154 Operation.newBuilder() 1155 .setName("batchUpdateIntentsTest") 1156 .setDone(true) 1157 .setResponse(Any.pack(expectedResponse)) 1158 .build(); 1159 mockService.addResponse(resultOperation); 1160 1161 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1162 String intentBatchUri = "intentBatchUri544125582"; 1163 1164 BatchUpdateIntentsResponse actualResponse = 1165 client.batchUpdateIntentsAsync(parent, intentBatchUri).get(); 1166 Assert.assertEquals(expectedResponse, actualResponse); 1167 1168 List<String> actualRequests = mockService.getRequestPaths(); 1169 Assert.assertEquals(1, actualRequests.size()); 1170 1171 String apiClientHeaderKey = 1172 mockService 1173 .getRequestHeaders() 1174 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1175 .iterator() 1176 .next(); 1177 Assert.assertTrue( 1178 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1179 .matcher(apiClientHeaderKey) 1180 .matches()); 1181 } 1182 1183 @Test batchUpdateIntentsExceptionTest2()1184 public void batchUpdateIntentsExceptionTest2() throws Exception { 1185 ApiException exception = 1186 ApiExceptionFactory.createException( 1187 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1188 mockService.addException(exception); 1189 1190 try { 1191 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1192 String intentBatchUri = "intentBatchUri544125582"; 1193 client.batchUpdateIntentsAsync(parent, intentBatchUri).get(); 1194 Assert.fail("No exception raised"); 1195 } catch (ExecutionException e) { 1196 } 1197 } 1198 1199 @Test batchUpdateIntentsTest3()1200 public void batchUpdateIntentsTest3() throws Exception { 1201 BatchUpdateIntentsResponse expectedResponse = 1202 BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build(); 1203 Operation resultOperation = 1204 Operation.newBuilder() 1205 .setName("batchUpdateIntentsTest") 1206 .setDone(true) 1207 .setResponse(Any.pack(expectedResponse)) 1208 .build(); 1209 mockService.addResponse(resultOperation); 1210 1211 String parent = "projects/project-2469/agent"; 1212 IntentBatch intentBatchInline = IntentBatch.newBuilder().build(); 1213 1214 BatchUpdateIntentsResponse actualResponse = 1215 client.batchUpdateIntentsAsync(parent, intentBatchInline).get(); 1216 Assert.assertEquals(expectedResponse, actualResponse); 1217 1218 List<String> actualRequests = mockService.getRequestPaths(); 1219 Assert.assertEquals(1, actualRequests.size()); 1220 1221 String apiClientHeaderKey = 1222 mockService 1223 .getRequestHeaders() 1224 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1225 .iterator() 1226 .next(); 1227 Assert.assertTrue( 1228 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1229 .matcher(apiClientHeaderKey) 1230 .matches()); 1231 } 1232 1233 @Test batchUpdateIntentsExceptionTest3()1234 public void batchUpdateIntentsExceptionTest3() throws Exception { 1235 ApiException exception = 1236 ApiExceptionFactory.createException( 1237 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1238 mockService.addException(exception); 1239 1240 try { 1241 String parent = "projects/project-2469/agent"; 1242 IntentBatch intentBatchInline = IntentBatch.newBuilder().build(); 1243 client.batchUpdateIntentsAsync(parent, intentBatchInline).get(); 1244 Assert.fail("No exception raised"); 1245 } catch (ExecutionException e) { 1246 } 1247 } 1248 1249 @Test batchUpdateIntentsTest4()1250 public void batchUpdateIntentsTest4() throws Exception { 1251 BatchUpdateIntentsResponse expectedResponse = 1252 BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build(); 1253 Operation resultOperation = 1254 Operation.newBuilder() 1255 .setName("batchUpdateIntentsTest") 1256 .setDone(true) 1257 .setResponse(Any.pack(expectedResponse)) 1258 .build(); 1259 mockService.addResponse(resultOperation); 1260 1261 String parent = "projects/project-2469/agent"; 1262 String intentBatchUri = "intentBatchUri544125582"; 1263 1264 BatchUpdateIntentsResponse actualResponse = 1265 client.batchUpdateIntentsAsync(parent, intentBatchUri).get(); 1266 Assert.assertEquals(expectedResponse, actualResponse); 1267 1268 List<String> actualRequests = mockService.getRequestPaths(); 1269 Assert.assertEquals(1, actualRequests.size()); 1270 1271 String apiClientHeaderKey = 1272 mockService 1273 .getRequestHeaders() 1274 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1275 .iterator() 1276 .next(); 1277 Assert.assertTrue( 1278 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1279 .matcher(apiClientHeaderKey) 1280 .matches()); 1281 } 1282 1283 @Test batchUpdateIntentsExceptionTest4()1284 public void batchUpdateIntentsExceptionTest4() throws Exception { 1285 ApiException exception = 1286 ApiExceptionFactory.createException( 1287 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1288 mockService.addException(exception); 1289 1290 try { 1291 String parent = "projects/project-2469/agent"; 1292 String intentBatchUri = "intentBatchUri544125582"; 1293 client.batchUpdateIntentsAsync(parent, intentBatchUri).get(); 1294 Assert.fail("No exception raised"); 1295 } catch (ExecutionException e) { 1296 } 1297 } 1298 1299 @Test batchDeleteIntentsTest()1300 public void batchDeleteIntentsTest() throws Exception { 1301 Empty expectedResponse = Empty.newBuilder().build(); 1302 Operation resultOperation = 1303 Operation.newBuilder() 1304 .setName("batchDeleteIntentsTest") 1305 .setDone(true) 1306 .setResponse(Any.pack(expectedResponse)) 1307 .build(); 1308 mockService.addResponse(resultOperation); 1309 1310 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1311 List<Intent> intents = new ArrayList<>(); 1312 1313 client.batchDeleteIntentsAsync(parent, intents).get(); 1314 1315 List<String> actualRequests = mockService.getRequestPaths(); 1316 Assert.assertEquals(1, actualRequests.size()); 1317 1318 String apiClientHeaderKey = 1319 mockService 1320 .getRequestHeaders() 1321 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1322 .iterator() 1323 .next(); 1324 Assert.assertTrue( 1325 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1326 .matcher(apiClientHeaderKey) 1327 .matches()); 1328 } 1329 1330 @Test batchDeleteIntentsExceptionTest()1331 public void batchDeleteIntentsExceptionTest() throws Exception { 1332 ApiException exception = 1333 ApiExceptionFactory.createException( 1334 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1335 mockService.addException(exception); 1336 1337 try { 1338 AgentName parent = AgentName.ofProjectName("[PROJECT]"); 1339 List<Intent> intents = new ArrayList<>(); 1340 client.batchDeleteIntentsAsync(parent, intents).get(); 1341 Assert.fail("No exception raised"); 1342 } catch (ExecutionException e) { 1343 } 1344 } 1345 1346 @Test batchDeleteIntentsTest2()1347 public void batchDeleteIntentsTest2() throws Exception { 1348 Empty expectedResponse = Empty.newBuilder().build(); 1349 Operation resultOperation = 1350 Operation.newBuilder() 1351 .setName("batchDeleteIntentsTest") 1352 .setDone(true) 1353 .setResponse(Any.pack(expectedResponse)) 1354 .build(); 1355 mockService.addResponse(resultOperation); 1356 1357 String parent = "projects/project-2469/agent"; 1358 List<Intent> intents = new ArrayList<>(); 1359 1360 client.batchDeleteIntentsAsync(parent, intents).get(); 1361 1362 List<String> actualRequests = mockService.getRequestPaths(); 1363 Assert.assertEquals(1, actualRequests.size()); 1364 1365 String apiClientHeaderKey = 1366 mockService 1367 .getRequestHeaders() 1368 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1369 .iterator() 1370 .next(); 1371 Assert.assertTrue( 1372 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1373 .matcher(apiClientHeaderKey) 1374 .matches()); 1375 } 1376 1377 @Test batchDeleteIntentsExceptionTest2()1378 public void batchDeleteIntentsExceptionTest2() throws Exception { 1379 ApiException exception = 1380 ApiExceptionFactory.createException( 1381 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1382 mockService.addException(exception); 1383 1384 try { 1385 String parent = "projects/project-2469/agent"; 1386 List<Intent> intents = new ArrayList<>(); 1387 client.batchDeleteIntentsAsync(parent, intents).get(); 1388 Assert.fail("No exception raised"); 1389 } catch (ExecutionException e) { 1390 } 1391 } 1392 1393 @Test listLocationsTest()1394 public void listLocationsTest() throws Exception { 1395 Location responsesElement = Location.newBuilder().build(); 1396 ListLocationsResponse expectedResponse = 1397 ListLocationsResponse.newBuilder() 1398 .setNextPageToken("") 1399 .addAllLocations(Arrays.asList(responsesElement)) 1400 .build(); 1401 mockService.addResponse(expectedResponse); 1402 1403 ListLocationsRequest request = 1404 ListLocationsRequest.newBuilder() 1405 .setName("projects/project-3664") 1406 .setFilter("filter-1274492040") 1407 .setPageSize(883849137) 1408 .setPageToken("pageToken873572522") 1409 .build(); 1410 1411 ListLocationsPagedResponse pagedListResponse = client.listLocations(request); 1412 1413 List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1414 1415 Assert.assertEquals(1, resources.size()); 1416 Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0)); 1417 1418 List<String> actualRequests = mockService.getRequestPaths(); 1419 Assert.assertEquals(1, actualRequests.size()); 1420 1421 String apiClientHeaderKey = 1422 mockService 1423 .getRequestHeaders() 1424 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1425 .iterator() 1426 .next(); 1427 Assert.assertTrue( 1428 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1429 .matcher(apiClientHeaderKey) 1430 .matches()); 1431 } 1432 1433 @Test listLocationsExceptionTest()1434 public void listLocationsExceptionTest() throws Exception { 1435 ApiException exception = 1436 ApiExceptionFactory.createException( 1437 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1438 mockService.addException(exception); 1439 1440 try { 1441 ListLocationsRequest request = 1442 ListLocationsRequest.newBuilder() 1443 .setName("projects/project-3664") 1444 .setFilter("filter-1274492040") 1445 .setPageSize(883849137) 1446 .setPageToken("pageToken873572522") 1447 .build(); 1448 client.listLocations(request); 1449 Assert.fail("No exception raised"); 1450 } catch (InvalidArgumentException e) { 1451 // Expected exception. 1452 } 1453 } 1454 1455 @Test getLocationTest()1456 public void getLocationTest() throws Exception { 1457 Location expectedResponse = 1458 Location.newBuilder() 1459 .setName("name3373707") 1460 .setLocationId("locationId1541836720") 1461 .setDisplayName("displayName1714148973") 1462 .putAllLabels(new HashMap<String, String>()) 1463 .setMetadata(Any.newBuilder().build()) 1464 .build(); 1465 mockService.addResponse(expectedResponse); 1466 1467 GetLocationRequest request = 1468 GetLocationRequest.newBuilder() 1469 .setName("projects/project-9062/locations/location-9062") 1470 .build(); 1471 1472 Location actualResponse = client.getLocation(request); 1473 Assert.assertEquals(expectedResponse, actualResponse); 1474 1475 List<String> actualRequests = mockService.getRequestPaths(); 1476 Assert.assertEquals(1, actualRequests.size()); 1477 1478 String apiClientHeaderKey = 1479 mockService 1480 .getRequestHeaders() 1481 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1482 .iterator() 1483 .next(); 1484 Assert.assertTrue( 1485 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1486 .matcher(apiClientHeaderKey) 1487 .matches()); 1488 } 1489 1490 @Test getLocationExceptionTest()1491 public void getLocationExceptionTest() throws Exception { 1492 ApiException exception = 1493 ApiExceptionFactory.createException( 1494 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1495 mockService.addException(exception); 1496 1497 try { 1498 GetLocationRequest request = 1499 GetLocationRequest.newBuilder() 1500 .setName("projects/project-9062/locations/location-9062") 1501 .build(); 1502 client.getLocation(request); 1503 Assert.fail("No exception raised"); 1504 } catch (InvalidArgumentException e) { 1505 // Expected exception. 1506 } 1507 } 1508 } 1509