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.ParticipantsClient.ListLocationsPagedResponse; 20 import static com.google.cloud.dialogflow.v2.ParticipantsClient.ListParticipantsPagedResponse; 21 22 import com.google.api.gax.core.NoCredentialsProvider; 23 import com.google.api.gax.grpc.GaxGrpcProperties; 24 import com.google.api.gax.grpc.testing.LocalChannelProvider; 25 import com.google.api.gax.grpc.testing.MockGrpcService; 26 import com.google.api.gax.grpc.testing.MockServiceHelper; 27 import com.google.api.gax.grpc.testing.MockStreamObserver; 28 import com.google.api.gax.rpc.ApiClientHeaderProvider; 29 import com.google.api.gax.rpc.ApiStreamObserver; 30 import com.google.api.gax.rpc.BidiStreamingCallable; 31 import com.google.api.gax.rpc.InvalidArgumentException; 32 import com.google.api.gax.rpc.StatusCode; 33 import com.google.cloud.location.GetLocationRequest; 34 import com.google.cloud.location.ListLocationsRequest; 35 import com.google.cloud.location.ListLocationsResponse; 36 import com.google.cloud.location.Location; 37 import com.google.common.collect.Lists; 38 import com.google.protobuf.AbstractMessage; 39 import com.google.protobuf.Any; 40 import com.google.protobuf.FieldMask; 41 import com.google.protobuf.Struct; 42 import io.grpc.StatusRuntimeException; 43 import java.io.IOException; 44 import java.util.ArrayList; 45 import java.util.Arrays; 46 import java.util.HashMap; 47 import java.util.List; 48 import java.util.UUID; 49 import java.util.concurrent.ExecutionException; 50 import javax.annotation.Generated; 51 import org.junit.After; 52 import org.junit.AfterClass; 53 import org.junit.Assert; 54 import org.junit.Before; 55 import org.junit.BeforeClass; 56 import org.junit.Test; 57 58 @Generated("by gapic-generator-java") 59 public class ParticipantsClientTest { 60 private static MockLocations mockLocations; 61 private static MockParticipants mockParticipants; 62 private static MockServiceHelper mockServiceHelper; 63 private LocalChannelProvider channelProvider; 64 private ParticipantsClient client; 65 66 @BeforeClass startStaticServer()67 public static void startStaticServer() { 68 mockParticipants = new MockParticipants(); 69 mockLocations = new MockLocations(); 70 mockServiceHelper = 71 new MockServiceHelper( 72 UUID.randomUUID().toString(), 73 Arrays.<MockGrpcService>asList(mockParticipants, mockLocations)); 74 mockServiceHelper.start(); 75 } 76 77 @AfterClass stopServer()78 public static void stopServer() { 79 mockServiceHelper.stop(); 80 } 81 82 @Before setUp()83 public void setUp() throws IOException { 84 mockServiceHelper.reset(); 85 channelProvider = mockServiceHelper.createChannelProvider(); 86 ParticipantsSettings settings = 87 ParticipantsSettings.newBuilder() 88 .setTransportChannelProvider(channelProvider) 89 .setCredentialsProvider(NoCredentialsProvider.create()) 90 .build(); 91 client = ParticipantsClient.create(settings); 92 } 93 94 @After tearDown()95 public void tearDown() throws Exception { 96 client.close(); 97 } 98 99 @Test createParticipantTest()100 public void createParticipantTest() throws Exception { 101 Participant expectedResponse = 102 Participant.newBuilder() 103 .setName( 104 ParticipantName.ofProjectConversationParticipantName( 105 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 106 .toString()) 107 .setSipRecordingMediaLabel("sipRecordingMediaLabel-1887770873") 108 .setObfuscatedExternalUserId("obfuscatedExternalUserId1778228693") 109 .putAllDocumentsMetadataFilters(new HashMap<String, String>()) 110 .build(); 111 mockParticipants.addResponse(expectedResponse); 112 113 ConversationName parent = 114 ConversationName.ofProjectConversationName("[PROJECT]", "[CONVERSATION]"); 115 Participant participant = Participant.newBuilder().build(); 116 117 Participant actualResponse = client.createParticipant(parent, participant); 118 Assert.assertEquals(expectedResponse, actualResponse); 119 120 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 121 Assert.assertEquals(1, actualRequests.size()); 122 CreateParticipantRequest actualRequest = ((CreateParticipantRequest) actualRequests.get(0)); 123 124 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 125 Assert.assertEquals(participant, actualRequest.getParticipant()); 126 Assert.assertTrue( 127 channelProvider.isHeaderSent( 128 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 129 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 130 } 131 132 @Test createParticipantExceptionTest()133 public void createParticipantExceptionTest() throws Exception { 134 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 135 mockParticipants.addException(exception); 136 137 try { 138 ConversationName parent = 139 ConversationName.ofProjectConversationName("[PROJECT]", "[CONVERSATION]"); 140 Participant participant = Participant.newBuilder().build(); 141 client.createParticipant(parent, participant); 142 Assert.fail("No exception raised"); 143 } catch (InvalidArgumentException e) { 144 // Expected exception. 145 } 146 } 147 148 @Test createParticipantTest2()149 public void createParticipantTest2() throws Exception { 150 Participant expectedResponse = 151 Participant.newBuilder() 152 .setName( 153 ParticipantName.ofProjectConversationParticipantName( 154 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 155 .toString()) 156 .setSipRecordingMediaLabel("sipRecordingMediaLabel-1887770873") 157 .setObfuscatedExternalUserId("obfuscatedExternalUserId1778228693") 158 .putAllDocumentsMetadataFilters(new HashMap<String, String>()) 159 .build(); 160 mockParticipants.addResponse(expectedResponse); 161 162 String parent = "parent-995424086"; 163 Participant participant = Participant.newBuilder().build(); 164 165 Participant actualResponse = client.createParticipant(parent, participant); 166 Assert.assertEquals(expectedResponse, actualResponse); 167 168 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 169 Assert.assertEquals(1, actualRequests.size()); 170 CreateParticipantRequest actualRequest = ((CreateParticipantRequest) actualRequests.get(0)); 171 172 Assert.assertEquals(parent, actualRequest.getParent()); 173 Assert.assertEquals(participant, actualRequest.getParticipant()); 174 Assert.assertTrue( 175 channelProvider.isHeaderSent( 176 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 177 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 178 } 179 180 @Test createParticipantExceptionTest2()181 public void createParticipantExceptionTest2() throws Exception { 182 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 183 mockParticipants.addException(exception); 184 185 try { 186 String parent = "parent-995424086"; 187 Participant participant = Participant.newBuilder().build(); 188 client.createParticipant(parent, participant); 189 Assert.fail("No exception raised"); 190 } catch (InvalidArgumentException e) { 191 // Expected exception. 192 } 193 } 194 195 @Test getParticipantTest()196 public void getParticipantTest() throws Exception { 197 Participant expectedResponse = 198 Participant.newBuilder() 199 .setName( 200 ParticipantName.ofProjectConversationParticipantName( 201 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 202 .toString()) 203 .setSipRecordingMediaLabel("sipRecordingMediaLabel-1887770873") 204 .setObfuscatedExternalUserId("obfuscatedExternalUserId1778228693") 205 .putAllDocumentsMetadataFilters(new HashMap<String, String>()) 206 .build(); 207 mockParticipants.addResponse(expectedResponse); 208 209 ParticipantName name = 210 ParticipantName.ofProjectConversationParticipantName( 211 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 212 213 Participant actualResponse = client.getParticipant(name); 214 Assert.assertEquals(expectedResponse, actualResponse); 215 216 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 217 Assert.assertEquals(1, actualRequests.size()); 218 GetParticipantRequest actualRequest = ((GetParticipantRequest) actualRequests.get(0)); 219 220 Assert.assertEquals(name.toString(), actualRequest.getName()); 221 Assert.assertTrue( 222 channelProvider.isHeaderSent( 223 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 224 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 225 } 226 227 @Test getParticipantExceptionTest()228 public void getParticipantExceptionTest() throws Exception { 229 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 230 mockParticipants.addException(exception); 231 232 try { 233 ParticipantName name = 234 ParticipantName.ofProjectConversationParticipantName( 235 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 236 client.getParticipant(name); 237 Assert.fail("No exception raised"); 238 } catch (InvalidArgumentException e) { 239 // Expected exception. 240 } 241 } 242 243 @Test getParticipantTest2()244 public void getParticipantTest2() throws Exception { 245 Participant expectedResponse = 246 Participant.newBuilder() 247 .setName( 248 ParticipantName.ofProjectConversationParticipantName( 249 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 250 .toString()) 251 .setSipRecordingMediaLabel("sipRecordingMediaLabel-1887770873") 252 .setObfuscatedExternalUserId("obfuscatedExternalUserId1778228693") 253 .putAllDocumentsMetadataFilters(new HashMap<String, String>()) 254 .build(); 255 mockParticipants.addResponse(expectedResponse); 256 257 String name = "name3373707"; 258 259 Participant actualResponse = client.getParticipant(name); 260 Assert.assertEquals(expectedResponse, actualResponse); 261 262 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 263 Assert.assertEquals(1, actualRequests.size()); 264 GetParticipantRequest actualRequest = ((GetParticipantRequest) actualRequests.get(0)); 265 266 Assert.assertEquals(name, actualRequest.getName()); 267 Assert.assertTrue( 268 channelProvider.isHeaderSent( 269 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 270 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 271 } 272 273 @Test getParticipantExceptionTest2()274 public void getParticipantExceptionTest2() throws Exception { 275 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 276 mockParticipants.addException(exception); 277 278 try { 279 String name = "name3373707"; 280 client.getParticipant(name); 281 Assert.fail("No exception raised"); 282 } catch (InvalidArgumentException e) { 283 // Expected exception. 284 } 285 } 286 287 @Test listParticipantsTest()288 public void listParticipantsTest() throws Exception { 289 Participant responsesElement = Participant.newBuilder().build(); 290 ListParticipantsResponse expectedResponse = 291 ListParticipantsResponse.newBuilder() 292 .setNextPageToken("") 293 .addAllParticipants(Arrays.asList(responsesElement)) 294 .build(); 295 mockParticipants.addResponse(expectedResponse); 296 297 ConversationName parent = 298 ConversationName.ofProjectConversationName("[PROJECT]", "[CONVERSATION]"); 299 300 ListParticipantsPagedResponse pagedListResponse = client.listParticipants(parent); 301 302 List<Participant> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 303 304 Assert.assertEquals(1, resources.size()); 305 Assert.assertEquals(expectedResponse.getParticipantsList().get(0), resources.get(0)); 306 307 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 308 Assert.assertEquals(1, actualRequests.size()); 309 ListParticipantsRequest actualRequest = ((ListParticipantsRequest) actualRequests.get(0)); 310 311 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 312 Assert.assertTrue( 313 channelProvider.isHeaderSent( 314 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 315 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 316 } 317 318 @Test listParticipantsExceptionTest()319 public void listParticipantsExceptionTest() throws Exception { 320 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 321 mockParticipants.addException(exception); 322 323 try { 324 ConversationName parent = 325 ConversationName.ofProjectConversationName("[PROJECT]", "[CONVERSATION]"); 326 client.listParticipants(parent); 327 Assert.fail("No exception raised"); 328 } catch (InvalidArgumentException e) { 329 // Expected exception. 330 } 331 } 332 333 @Test listParticipantsTest2()334 public void listParticipantsTest2() throws Exception { 335 Participant responsesElement = Participant.newBuilder().build(); 336 ListParticipantsResponse expectedResponse = 337 ListParticipantsResponse.newBuilder() 338 .setNextPageToken("") 339 .addAllParticipants(Arrays.asList(responsesElement)) 340 .build(); 341 mockParticipants.addResponse(expectedResponse); 342 343 String parent = "parent-995424086"; 344 345 ListParticipantsPagedResponse pagedListResponse = client.listParticipants(parent); 346 347 List<Participant> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 348 349 Assert.assertEquals(1, resources.size()); 350 Assert.assertEquals(expectedResponse.getParticipantsList().get(0), resources.get(0)); 351 352 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 353 Assert.assertEquals(1, actualRequests.size()); 354 ListParticipantsRequest actualRequest = ((ListParticipantsRequest) actualRequests.get(0)); 355 356 Assert.assertEquals(parent, actualRequest.getParent()); 357 Assert.assertTrue( 358 channelProvider.isHeaderSent( 359 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 360 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 361 } 362 363 @Test listParticipantsExceptionTest2()364 public void listParticipantsExceptionTest2() throws Exception { 365 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 366 mockParticipants.addException(exception); 367 368 try { 369 String parent = "parent-995424086"; 370 client.listParticipants(parent); 371 Assert.fail("No exception raised"); 372 } catch (InvalidArgumentException e) { 373 // Expected exception. 374 } 375 } 376 377 @Test updateParticipantTest()378 public void updateParticipantTest() throws Exception { 379 Participant expectedResponse = 380 Participant.newBuilder() 381 .setName( 382 ParticipantName.ofProjectConversationParticipantName( 383 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 384 .toString()) 385 .setSipRecordingMediaLabel("sipRecordingMediaLabel-1887770873") 386 .setObfuscatedExternalUserId("obfuscatedExternalUserId1778228693") 387 .putAllDocumentsMetadataFilters(new HashMap<String, String>()) 388 .build(); 389 mockParticipants.addResponse(expectedResponse); 390 391 Participant participant = Participant.newBuilder().build(); 392 FieldMask updateMask = FieldMask.newBuilder().build(); 393 394 Participant actualResponse = client.updateParticipant(participant, updateMask); 395 Assert.assertEquals(expectedResponse, actualResponse); 396 397 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 398 Assert.assertEquals(1, actualRequests.size()); 399 UpdateParticipantRequest actualRequest = ((UpdateParticipantRequest) actualRequests.get(0)); 400 401 Assert.assertEquals(participant, actualRequest.getParticipant()); 402 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 403 Assert.assertTrue( 404 channelProvider.isHeaderSent( 405 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 406 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 407 } 408 409 @Test updateParticipantExceptionTest()410 public void updateParticipantExceptionTest() throws Exception { 411 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 412 mockParticipants.addException(exception); 413 414 try { 415 Participant participant = Participant.newBuilder().build(); 416 FieldMask updateMask = FieldMask.newBuilder().build(); 417 client.updateParticipant(participant, updateMask); 418 Assert.fail("No exception raised"); 419 } catch (InvalidArgumentException e) { 420 // Expected exception. 421 } 422 } 423 424 @Test analyzeContentTest()425 public void analyzeContentTest() throws Exception { 426 AnalyzeContentResponse expectedResponse = 427 AnalyzeContentResponse.newBuilder() 428 .setReplyText("replyText-433699017") 429 .setReplyAudio(OutputAudio.newBuilder().build()) 430 .setAutomatedAgentReply(AutomatedAgentReply.newBuilder().build()) 431 .setMessage(Message.newBuilder().build()) 432 .addAllHumanAgentSuggestionResults(new ArrayList<SuggestionResult>()) 433 .addAllEndUserSuggestionResults(new ArrayList<SuggestionResult>()) 434 .setDtmfParameters(DtmfParameters.newBuilder().build()) 435 .build(); 436 mockParticipants.addResponse(expectedResponse); 437 438 ParticipantName participant = 439 ParticipantName.ofProjectConversationParticipantName( 440 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 441 EventInput eventInput = EventInput.newBuilder().build(); 442 443 AnalyzeContentResponse actualResponse = client.analyzeContent(participant, eventInput); 444 Assert.assertEquals(expectedResponse, actualResponse); 445 446 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 447 Assert.assertEquals(1, actualRequests.size()); 448 AnalyzeContentRequest actualRequest = ((AnalyzeContentRequest) actualRequests.get(0)); 449 450 Assert.assertEquals(participant.toString(), actualRequest.getParticipant()); 451 Assert.assertEquals(eventInput, actualRequest.getEventInput()); 452 Assert.assertTrue( 453 channelProvider.isHeaderSent( 454 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 455 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 456 } 457 458 @Test analyzeContentExceptionTest()459 public void analyzeContentExceptionTest() throws Exception { 460 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 461 mockParticipants.addException(exception); 462 463 try { 464 ParticipantName participant = 465 ParticipantName.ofProjectConversationParticipantName( 466 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 467 EventInput eventInput = EventInput.newBuilder().build(); 468 client.analyzeContent(participant, eventInput); 469 Assert.fail("No exception raised"); 470 } catch (InvalidArgumentException e) { 471 // Expected exception. 472 } 473 } 474 475 @Test analyzeContentTest2()476 public void analyzeContentTest2() throws Exception { 477 AnalyzeContentResponse expectedResponse = 478 AnalyzeContentResponse.newBuilder() 479 .setReplyText("replyText-433699017") 480 .setReplyAudio(OutputAudio.newBuilder().build()) 481 .setAutomatedAgentReply(AutomatedAgentReply.newBuilder().build()) 482 .setMessage(Message.newBuilder().build()) 483 .addAllHumanAgentSuggestionResults(new ArrayList<SuggestionResult>()) 484 .addAllEndUserSuggestionResults(new ArrayList<SuggestionResult>()) 485 .setDtmfParameters(DtmfParameters.newBuilder().build()) 486 .build(); 487 mockParticipants.addResponse(expectedResponse); 488 489 ParticipantName participant = 490 ParticipantName.ofProjectConversationParticipantName( 491 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 492 TextInput textInput = TextInput.newBuilder().build(); 493 494 AnalyzeContentResponse actualResponse = client.analyzeContent(participant, textInput); 495 Assert.assertEquals(expectedResponse, actualResponse); 496 497 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 498 Assert.assertEquals(1, actualRequests.size()); 499 AnalyzeContentRequest actualRequest = ((AnalyzeContentRequest) actualRequests.get(0)); 500 501 Assert.assertEquals(participant.toString(), actualRequest.getParticipant()); 502 Assert.assertEquals(textInput, actualRequest.getTextInput()); 503 Assert.assertTrue( 504 channelProvider.isHeaderSent( 505 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 506 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 507 } 508 509 @Test analyzeContentExceptionTest2()510 public void analyzeContentExceptionTest2() throws Exception { 511 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 512 mockParticipants.addException(exception); 513 514 try { 515 ParticipantName participant = 516 ParticipantName.ofProjectConversationParticipantName( 517 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 518 TextInput textInput = TextInput.newBuilder().build(); 519 client.analyzeContent(participant, textInput); 520 Assert.fail("No exception raised"); 521 } catch (InvalidArgumentException e) { 522 // Expected exception. 523 } 524 } 525 526 @Test analyzeContentTest3()527 public void analyzeContentTest3() throws Exception { 528 AnalyzeContentResponse expectedResponse = 529 AnalyzeContentResponse.newBuilder() 530 .setReplyText("replyText-433699017") 531 .setReplyAudio(OutputAudio.newBuilder().build()) 532 .setAutomatedAgentReply(AutomatedAgentReply.newBuilder().build()) 533 .setMessage(Message.newBuilder().build()) 534 .addAllHumanAgentSuggestionResults(new ArrayList<SuggestionResult>()) 535 .addAllEndUserSuggestionResults(new ArrayList<SuggestionResult>()) 536 .setDtmfParameters(DtmfParameters.newBuilder().build()) 537 .build(); 538 mockParticipants.addResponse(expectedResponse); 539 540 String participant = "participant767422259"; 541 EventInput eventInput = EventInput.newBuilder().build(); 542 543 AnalyzeContentResponse actualResponse = client.analyzeContent(participant, eventInput); 544 Assert.assertEquals(expectedResponse, actualResponse); 545 546 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 547 Assert.assertEquals(1, actualRequests.size()); 548 AnalyzeContentRequest actualRequest = ((AnalyzeContentRequest) actualRequests.get(0)); 549 550 Assert.assertEquals(participant, actualRequest.getParticipant()); 551 Assert.assertEquals(eventInput, actualRequest.getEventInput()); 552 Assert.assertTrue( 553 channelProvider.isHeaderSent( 554 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 555 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 556 } 557 558 @Test analyzeContentExceptionTest3()559 public void analyzeContentExceptionTest3() throws Exception { 560 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 561 mockParticipants.addException(exception); 562 563 try { 564 String participant = "participant767422259"; 565 EventInput eventInput = EventInput.newBuilder().build(); 566 client.analyzeContent(participant, eventInput); 567 Assert.fail("No exception raised"); 568 } catch (InvalidArgumentException e) { 569 // Expected exception. 570 } 571 } 572 573 @Test analyzeContentTest4()574 public void analyzeContentTest4() throws Exception { 575 AnalyzeContentResponse expectedResponse = 576 AnalyzeContentResponse.newBuilder() 577 .setReplyText("replyText-433699017") 578 .setReplyAudio(OutputAudio.newBuilder().build()) 579 .setAutomatedAgentReply(AutomatedAgentReply.newBuilder().build()) 580 .setMessage(Message.newBuilder().build()) 581 .addAllHumanAgentSuggestionResults(new ArrayList<SuggestionResult>()) 582 .addAllEndUserSuggestionResults(new ArrayList<SuggestionResult>()) 583 .setDtmfParameters(DtmfParameters.newBuilder().build()) 584 .build(); 585 mockParticipants.addResponse(expectedResponse); 586 587 String participant = "participant767422259"; 588 TextInput textInput = TextInput.newBuilder().build(); 589 590 AnalyzeContentResponse actualResponse = client.analyzeContent(participant, textInput); 591 Assert.assertEquals(expectedResponse, actualResponse); 592 593 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 594 Assert.assertEquals(1, actualRequests.size()); 595 AnalyzeContentRequest actualRequest = ((AnalyzeContentRequest) actualRequests.get(0)); 596 597 Assert.assertEquals(participant, actualRequest.getParticipant()); 598 Assert.assertEquals(textInput, actualRequest.getTextInput()); 599 Assert.assertTrue( 600 channelProvider.isHeaderSent( 601 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 602 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 603 } 604 605 @Test analyzeContentExceptionTest4()606 public void analyzeContentExceptionTest4() throws Exception { 607 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 608 mockParticipants.addException(exception); 609 610 try { 611 String participant = "participant767422259"; 612 TextInput textInput = TextInput.newBuilder().build(); 613 client.analyzeContent(participant, textInput); 614 Assert.fail("No exception raised"); 615 } catch (InvalidArgumentException e) { 616 // Expected exception. 617 } 618 } 619 620 @Test streamingAnalyzeContentTest()621 public void streamingAnalyzeContentTest() throws Exception { 622 StreamingAnalyzeContentResponse expectedResponse = 623 StreamingAnalyzeContentResponse.newBuilder() 624 .setRecognitionResult(StreamingRecognitionResult.newBuilder().build()) 625 .setReplyText("replyText-433699017") 626 .setReplyAudio(OutputAudio.newBuilder().build()) 627 .setAutomatedAgentReply(AutomatedAgentReply.newBuilder().build()) 628 .setMessage(Message.newBuilder().build()) 629 .addAllHumanAgentSuggestionResults(new ArrayList<SuggestionResult>()) 630 .addAllEndUserSuggestionResults(new ArrayList<SuggestionResult>()) 631 .setDtmfParameters(DtmfParameters.newBuilder().build()) 632 .setDebuggingInfo(CloudConversationDebuggingInfo.newBuilder().build()) 633 .build(); 634 mockParticipants.addResponse(expectedResponse); 635 StreamingAnalyzeContentRequest request = 636 StreamingAnalyzeContentRequest.newBuilder() 637 .setParticipant( 638 ParticipantName.ofProjectConversationParticipantName( 639 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 640 .toString()) 641 .setReplyAudioConfig(OutputAudioConfig.newBuilder().build()) 642 .setQueryParams(QueryParameters.newBuilder().build()) 643 .setAssistQueryParams(AssistQueryParameters.newBuilder().build()) 644 .setCxParameters(Struct.newBuilder().build()) 645 .setEnablePartialAutomatedAgentReply(true) 646 .setEnableDebuggingInfo(true) 647 .build(); 648 649 MockStreamObserver<StreamingAnalyzeContentResponse> responseObserver = 650 new MockStreamObserver<>(); 651 652 BidiStreamingCallable<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse> 653 callable = client.streamingAnalyzeContentCallable(); 654 ApiStreamObserver<StreamingAnalyzeContentRequest> requestObserver = 655 callable.bidiStreamingCall(responseObserver); 656 657 requestObserver.onNext(request); 658 requestObserver.onCompleted(); 659 660 List<StreamingAnalyzeContentResponse> actualResponses = responseObserver.future().get(); 661 Assert.assertEquals(1, actualResponses.size()); 662 Assert.assertEquals(expectedResponse, actualResponses.get(0)); 663 } 664 665 @Test streamingAnalyzeContentExceptionTest()666 public void streamingAnalyzeContentExceptionTest() throws Exception { 667 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 668 mockParticipants.addException(exception); 669 StreamingAnalyzeContentRequest request = 670 StreamingAnalyzeContentRequest.newBuilder() 671 .setParticipant( 672 ParticipantName.ofProjectConversationParticipantName( 673 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]") 674 .toString()) 675 .setReplyAudioConfig(OutputAudioConfig.newBuilder().build()) 676 .setQueryParams(QueryParameters.newBuilder().build()) 677 .setAssistQueryParams(AssistQueryParameters.newBuilder().build()) 678 .setCxParameters(Struct.newBuilder().build()) 679 .setEnablePartialAutomatedAgentReply(true) 680 .setEnableDebuggingInfo(true) 681 .build(); 682 683 MockStreamObserver<StreamingAnalyzeContentResponse> responseObserver = 684 new MockStreamObserver<>(); 685 686 BidiStreamingCallable<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse> 687 callable = client.streamingAnalyzeContentCallable(); 688 ApiStreamObserver<StreamingAnalyzeContentRequest> requestObserver = 689 callable.bidiStreamingCall(responseObserver); 690 691 requestObserver.onNext(request); 692 693 try { 694 List<StreamingAnalyzeContentResponse> actualResponses = responseObserver.future().get(); 695 Assert.fail("No exception thrown"); 696 } catch (ExecutionException e) { 697 Assert.assertTrue(e.getCause() instanceof InvalidArgumentException); 698 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 699 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 700 } 701 } 702 703 @Test suggestArticlesTest()704 public void suggestArticlesTest() throws Exception { 705 SuggestArticlesResponse expectedResponse = 706 SuggestArticlesResponse.newBuilder() 707 .addAllArticleAnswers(new ArrayList<ArticleAnswer>()) 708 .setLatestMessage("latestMessage-1424305536") 709 .setContextSize(1116903569) 710 .build(); 711 mockParticipants.addResponse(expectedResponse); 712 713 ParticipantName parent = 714 ParticipantName.ofProjectConversationParticipantName( 715 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 716 717 SuggestArticlesResponse actualResponse = client.suggestArticles(parent); 718 Assert.assertEquals(expectedResponse, actualResponse); 719 720 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 721 Assert.assertEquals(1, actualRequests.size()); 722 SuggestArticlesRequest actualRequest = ((SuggestArticlesRequest) actualRequests.get(0)); 723 724 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 725 Assert.assertTrue( 726 channelProvider.isHeaderSent( 727 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 728 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 729 } 730 731 @Test suggestArticlesExceptionTest()732 public void suggestArticlesExceptionTest() throws Exception { 733 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 734 mockParticipants.addException(exception); 735 736 try { 737 ParticipantName parent = 738 ParticipantName.ofProjectConversationParticipantName( 739 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 740 client.suggestArticles(parent); 741 Assert.fail("No exception raised"); 742 } catch (InvalidArgumentException e) { 743 // Expected exception. 744 } 745 } 746 747 @Test suggestArticlesTest2()748 public void suggestArticlesTest2() throws Exception { 749 SuggestArticlesResponse expectedResponse = 750 SuggestArticlesResponse.newBuilder() 751 .addAllArticleAnswers(new ArrayList<ArticleAnswer>()) 752 .setLatestMessage("latestMessage-1424305536") 753 .setContextSize(1116903569) 754 .build(); 755 mockParticipants.addResponse(expectedResponse); 756 757 String parent = "parent-995424086"; 758 759 SuggestArticlesResponse actualResponse = client.suggestArticles(parent); 760 Assert.assertEquals(expectedResponse, actualResponse); 761 762 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 763 Assert.assertEquals(1, actualRequests.size()); 764 SuggestArticlesRequest actualRequest = ((SuggestArticlesRequest) actualRequests.get(0)); 765 766 Assert.assertEquals(parent, actualRequest.getParent()); 767 Assert.assertTrue( 768 channelProvider.isHeaderSent( 769 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 770 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 771 } 772 773 @Test suggestArticlesExceptionTest2()774 public void suggestArticlesExceptionTest2() throws Exception { 775 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 776 mockParticipants.addException(exception); 777 778 try { 779 String parent = "parent-995424086"; 780 client.suggestArticles(parent); 781 Assert.fail("No exception raised"); 782 } catch (InvalidArgumentException e) { 783 // Expected exception. 784 } 785 } 786 787 @Test suggestFaqAnswersTest()788 public void suggestFaqAnswersTest() throws Exception { 789 SuggestFaqAnswersResponse expectedResponse = 790 SuggestFaqAnswersResponse.newBuilder() 791 .addAllFaqAnswers(new ArrayList<FaqAnswer>()) 792 .setLatestMessage("latestMessage-1424305536") 793 .setContextSize(1116903569) 794 .build(); 795 mockParticipants.addResponse(expectedResponse); 796 797 ParticipantName parent = 798 ParticipantName.ofProjectConversationParticipantName( 799 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 800 801 SuggestFaqAnswersResponse actualResponse = client.suggestFaqAnswers(parent); 802 Assert.assertEquals(expectedResponse, actualResponse); 803 804 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 805 Assert.assertEquals(1, actualRequests.size()); 806 SuggestFaqAnswersRequest actualRequest = ((SuggestFaqAnswersRequest) actualRequests.get(0)); 807 808 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 809 Assert.assertTrue( 810 channelProvider.isHeaderSent( 811 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 812 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 813 } 814 815 @Test suggestFaqAnswersExceptionTest()816 public void suggestFaqAnswersExceptionTest() throws Exception { 817 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 818 mockParticipants.addException(exception); 819 820 try { 821 ParticipantName parent = 822 ParticipantName.ofProjectConversationParticipantName( 823 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 824 client.suggestFaqAnswers(parent); 825 Assert.fail("No exception raised"); 826 } catch (InvalidArgumentException e) { 827 // Expected exception. 828 } 829 } 830 831 @Test suggestFaqAnswersTest2()832 public void suggestFaqAnswersTest2() throws Exception { 833 SuggestFaqAnswersResponse expectedResponse = 834 SuggestFaqAnswersResponse.newBuilder() 835 .addAllFaqAnswers(new ArrayList<FaqAnswer>()) 836 .setLatestMessage("latestMessage-1424305536") 837 .setContextSize(1116903569) 838 .build(); 839 mockParticipants.addResponse(expectedResponse); 840 841 String parent = "parent-995424086"; 842 843 SuggestFaqAnswersResponse actualResponse = client.suggestFaqAnswers(parent); 844 Assert.assertEquals(expectedResponse, actualResponse); 845 846 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 847 Assert.assertEquals(1, actualRequests.size()); 848 SuggestFaqAnswersRequest actualRequest = ((SuggestFaqAnswersRequest) actualRequests.get(0)); 849 850 Assert.assertEquals(parent, actualRequest.getParent()); 851 Assert.assertTrue( 852 channelProvider.isHeaderSent( 853 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 854 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 855 } 856 857 @Test suggestFaqAnswersExceptionTest2()858 public void suggestFaqAnswersExceptionTest2() throws Exception { 859 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 860 mockParticipants.addException(exception); 861 862 try { 863 String parent = "parent-995424086"; 864 client.suggestFaqAnswers(parent); 865 Assert.fail("No exception raised"); 866 } catch (InvalidArgumentException e) { 867 // Expected exception. 868 } 869 } 870 871 @Test suggestSmartRepliesTest()872 public void suggestSmartRepliesTest() throws Exception { 873 SuggestSmartRepliesResponse expectedResponse = 874 SuggestSmartRepliesResponse.newBuilder() 875 .addAllSmartReplyAnswers(new ArrayList<SmartReplyAnswer>()) 876 .setLatestMessage( 877 MessageName.ofProjectConversationMessageName( 878 "[PROJECT]", "[CONVERSATION]", "[MESSAGE]") 879 .toString()) 880 .setContextSize(1116903569) 881 .build(); 882 mockParticipants.addResponse(expectedResponse); 883 884 ParticipantName parent = 885 ParticipantName.ofProjectConversationParticipantName( 886 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 887 888 SuggestSmartRepliesResponse actualResponse = client.suggestSmartReplies(parent); 889 Assert.assertEquals(expectedResponse, actualResponse); 890 891 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 892 Assert.assertEquals(1, actualRequests.size()); 893 SuggestSmartRepliesRequest actualRequest = ((SuggestSmartRepliesRequest) actualRequests.get(0)); 894 895 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 896 Assert.assertTrue( 897 channelProvider.isHeaderSent( 898 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 899 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 900 } 901 902 @Test suggestSmartRepliesExceptionTest()903 public void suggestSmartRepliesExceptionTest() throws Exception { 904 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 905 mockParticipants.addException(exception); 906 907 try { 908 ParticipantName parent = 909 ParticipantName.ofProjectConversationParticipantName( 910 "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]"); 911 client.suggestSmartReplies(parent); 912 Assert.fail("No exception raised"); 913 } catch (InvalidArgumentException e) { 914 // Expected exception. 915 } 916 } 917 918 @Test suggestSmartRepliesTest2()919 public void suggestSmartRepliesTest2() throws Exception { 920 SuggestSmartRepliesResponse expectedResponse = 921 SuggestSmartRepliesResponse.newBuilder() 922 .addAllSmartReplyAnswers(new ArrayList<SmartReplyAnswer>()) 923 .setLatestMessage( 924 MessageName.ofProjectConversationMessageName( 925 "[PROJECT]", "[CONVERSATION]", "[MESSAGE]") 926 .toString()) 927 .setContextSize(1116903569) 928 .build(); 929 mockParticipants.addResponse(expectedResponse); 930 931 String parent = "parent-995424086"; 932 933 SuggestSmartRepliesResponse actualResponse = client.suggestSmartReplies(parent); 934 Assert.assertEquals(expectedResponse, actualResponse); 935 936 List<AbstractMessage> actualRequests = mockParticipants.getRequests(); 937 Assert.assertEquals(1, actualRequests.size()); 938 SuggestSmartRepliesRequest actualRequest = ((SuggestSmartRepliesRequest) actualRequests.get(0)); 939 940 Assert.assertEquals(parent, actualRequest.getParent()); 941 Assert.assertTrue( 942 channelProvider.isHeaderSent( 943 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 944 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 945 } 946 947 @Test suggestSmartRepliesExceptionTest2()948 public void suggestSmartRepliesExceptionTest2() throws Exception { 949 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 950 mockParticipants.addException(exception); 951 952 try { 953 String parent = "parent-995424086"; 954 client.suggestSmartReplies(parent); 955 Assert.fail("No exception raised"); 956 } catch (InvalidArgumentException e) { 957 // Expected exception. 958 } 959 } 960 961 @Test listLocationsTest()962 public void listLocationsTest() throws Exception { 963 Location responsesElement = Location.newBuilder().build(); 964 ListLocationsResponse expectedResponse = 965 ListLocationsResponse.newBuilder() 966 .setNextPageToken("") 967 .addAllLocations(Arrays.asList(responsesElement)) 968 .build(); 969 mockLocations.addResponse(expectedResponse); 970 971 ListLocationsRequest request = 972 ListLocationsRequest.newBuilder() 973 .setName("name3373707") 974 .setFilter("filter-1274492040") 975 .setPageSize(883849137) 976 .setPageToken("pageToken873572522") 977 .build(); 978 979 ListLocationsPagedResponse pagedListResponse = client.listLocations(request); 980 981 List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 982 983 Assert.assertEquals(1, resources.size()); 984 Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0)); 985 986 List<AbstractMessage> actualRequests = mockLocations.getRequests(); 987 Assert.assertEquals(1, actualRequests.size()); 988 ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0)); 989 990 Assert.assertEquals(request.getName(), actualRequest.getName()); 991 Assert.assertEquals(request.getFilter(), actualRequest.getFilter()); 992 Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); 993 Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); 994 Assert.assertTrue( 995 channelProvider.isHeaderSent( 996 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 997 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 998 } 999 1000 @Test listLocationsExceptionTest()1001 public void listLocationsExceptionTest() throws Exception { 1002 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1003 mockLocations.addException(exception); 1004 1005 try { 1006 ListLocationsRequest request = 1007 ListLocationsRequest.newBuilder() 1008 .setName("name3373707") 1009 .setFilter("filter-1274492040") 1010 .setPageSize(883849137) 1011 .setPageToken("pageToken873572522") 1012 .build(); 1013 client.listLocations(request); 1014 Assert.fail("No exception raised"); 1015 } catch (InvalidArgumentException e) { 1016 // Expected exception. 1017 } 1018 } 1019 1020 @Test getLocationTest()1021 public void getLocationTest() throws Exception { 1022 Location expectedResponse = 1023 Location.newBuilder() 1024 .setName("name3373707") 1025 .setLocationId("locationId1541836720") 1026 .setDisplayName("displayName1714148973") 1027 .putAllLabels(new HashMap<String, String>()) 1028 .setMetadata(Any.newBuilder().build()) 1029 .build(); 1030 mockLocations.addResponse(expectedResponse); 1031 1032 GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 1033 1034 Location actualResponse = client.getLocation(request); 1035 Assert.assertEquals(expectedResponse, actualResponse); 1036 1037 List<AbstractMessage> actualRequests = mockLocations.getRequests(); 1038 Assert.assertEquals(1, actualRequests.size()); 1039 GetLocationRequest actualRequest = ((GetLocationRequest) actualRequests.get(0)); 1040 1041 Assert.assertEquals(request.getName(), actualRequest.getName()); 1042 Assert.assertTrue( 1043 channelProvider.isHeaderSent( 1044 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1045 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1046 } 1047 1048 @Test getLocationExceptionTest()1049 public void getLocationExceptionTest() throws Exception { 1050 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1051 mockLocations.addException(exception); 1052 1053 try { 1054 GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 1055 client.getLocation(request); 1056 Assert.fail("No exception raised"); 1057 } catch (InvalidArgumentException e) { 1058 // Expected exception. 1059 } 1060 } 1061 } 1062