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.recommender.v1; 18 19 import static com.google.cloud.recommender.v1.RecommenderClient.ListInsightsPagedResponse; 20 import static com.google.cloud.recommender.v1.RecommenderClient.ListRecommendationsPagedResponse; 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.rpc.ApiClientHeaderProvider; 28 import com.google.api.gax.rpc.InvalidArgumentException; 29 import com.google.common.collect.Lists; 30 import com.google.protobuf.AbstractMessage; 31 import com.google.protobuf.Duration; 32 import com.google.protobuf.FieldMask; 33 import com.google.protobuf.Struct; 34 import com.google.protobuf.Timestamp; 35 import io.grpc.StatusRuntimeException; 36 import java.io.IOException; 37 import java.util.ArrayList; 38 import java.util.Arrays; 39 import java.util.HashMap; 40 import java.util.List; 41 import java.util.Map; 42 import java.util.UUID; 43 import javax.annotation.Generated; 44 import org.junit.After; 45 import org.junit.AfterClass; 46 import org.junit.Assert; 47 import org.junit.Before; 48 import org.junit.BeforeClass; 49 import org.junit.Test; 50 51 @Generated("by gapic-generator-java") 52 public class RecommenderClientTest { 53 private static MockRecommender mockRecommender; 54 private static MockServiceHelper mockServiceHelper; 55 private LocalChannelProvider channelProvider; 56 private RecommenderClient client; 57 58 @BeforeClass startStaticServer()59 public static void startStaticServer() { 60 mockRecommender = new MockRecommender(); 61 mockServiceHelper = 62 new MockServiceHelper( 63 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockRecommender)); 64 mockServiceHelper.start(); 65 } 66 67 @AfterClass stopServer()68 public static void stopServer() { 69 mockServiceHelper.stop(); 70 } 71 72 @Before setUp()73 public void setUp() throws IOException { 74 mockServiceHelper.reset(); 75 channelProvider = mockServiceHelper.createChannelProvider(); 76 RecommenderSettings settings = 77 RecommenderSettings.newBuilder() 78 .setTransportChannelProvider(channelProvider) 79 .setCredentialsProvider(NoCredentialsProvider.create()) 80 .build(); 81 client = RecommenderClient.create(settings); 82 } 83 84 @After tearDown()85 public void tearDown() throws Exception { 86 client.close(); 87 } 88 89 @Test listInsightsTest()90 public void listInsightsTest() throws Exception { 91 Insight responsesElement = Insight.newBuilder().build(); 92 ListInsightsResponse expectedResponse = 93 ListInsightsResponse.newBuilder() 94 .setNextPageToken("") 95 .addAllInsights(Arrays.asList(responsesElement)) 96 .build(); 97 mockRecommender.addResponse(expectedResponse); 98 99 InsightTypeName parent = 100 InsightTypeName.ofProjectLocationInsightTypeName( 101 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]"); 102 103 ListInsightsPagedResponse pagedListResponse = client.listInsights(parent); 104 105 List<Insight> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 106 107 Assert.assertEquals(1, resources.size()); 108 Assert.assertEquals(expectedResponse.getInsightsList().get(0), resources.get(0)); 109 110 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 111 Assert.assertEquals(1, actualRequests.size()); 112 ListInsightsRequest actualRequest = ((ListInsightsRequest) actualRequests.get(0)); 113 114 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 115 Assert.assertTrue( 116 channelProvider.isHeaderSent( 117 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 118 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 119 } 120 121 @Test listInsightsExceptionTest()122 public void listInsightsExceptionTest() throws Exception { 123 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 124 mockRecommender.addException(exception); 125 126 try { 127 InsightTypeName parent = 128 InsightTypeName.ofProjectLocationInsightTypeName( 129 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]"); 130 client.listInsights(parent); 131 Assert.fail("No exception raised"); 132 } catch (InvalidArgumentException e) { 133 // Expected exception. 134 } 135 } 136 137 @Test listInsightsTest2()138 public void listInsightsTest2() throws Exception { 139 Insight responsesElement = Insight.newBuilder().build(); 140 ListInsightsResponse expectedResponse = 141 ListInsightsResponse.newBuilder() 142 .setNextPageToken("") 143 .addAllInsights(Arrays.asList(responsesElement)) 144 .build(); 145 mockRecommender.addResponse(expectedResponse); 146 147 String parent = "parent-995424086"; 148 149 ListInsightsPagedResponse pagedListResponse = client.listInsights(parent); 150 151 List<Insight> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 152 153 Assert.assertEquals(1, resources.size()); 154 Assert.assertEquals(expectedResponse.getInsightsList().get(0), resources.get(0)); 155 156 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 157 Assert.assertEquals(1, actualRequests.size()); 158 ListInsightsRequest actualRequest = ((ListInsightsRequest) actualRequests.get(0)); 159 160 Assert.assertEquals(parent, actualRequest.getParent()); 161 Assert.assertTrue( 162 channelProvider.isHeaderSent( 163 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 164 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 165 } 166 167 @Test listInsightsExceptionTest2()168 public void listInsightsExceptionTest2() throws Exception { 169 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 170 mockRecommender.addException(exception); 171 172 try { 173 String parent = "parent-995424086"; 174 client.listInsights(parent); 175 Assert.fail("No exception raised"); 176 } catch (InvalidArgumentException e) { 177 // Expected exception. 178 } 179 } 180 181 @Test getInsightTest()182 public void getInsightTest() throws Exception { 183 Insight expectedResponse = 184 Insight.newBuilder() 185 .setName( 186 InsightName.ofProjectLocationInsightTypeInsightName( 187 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]") 188 .toString()) 189 .setDescription("description-1724546052") 190 .addAllTargetResources(new ArrayList<String>()) 191 .setInsightSubtype("insightSubtype841535170") 192 .setContent(Struct.newBuilder().build()) 193 .setLastRefreshTime(Timestamp.newBuilder().build()) 194 .setObservationPeriod(Duration.newBuilder().build()) 195 .setStateInfo(InsightStateInfo.newBuilder().build()) 196 .setEtag("etag3123477") 197 .addAllAssociatedRecommendations(new ArrayList<Insight.RecommendationReference>()) 198 .build(); 199 mockRecommender.addResponse(expectedResponse); 200 201 InsightName name = 202 InsightName.ofProjectLocationInsightTypeInsightName( 203 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]"); 204 205 Insight actualResponse = client.getInsight(name); 206 Assert.assertEquals(expectedResponse, actualResponse); 207 208 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 209 Assert.assertEquals(1, actualRequests.size()); 210 GetInsightRequest actualRequest = ((GetInsightRequest) actualRequests.get(0)); 211 212 Assert.assertEquals(name.toString(), actualRequest.getName()); 213 Assert.assertTrue( 214 channelProvider.isHeaderSent( 215 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 216 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 217 } 218 219 @Test getInsightExceptionTest()220 public void getInsightExceptionTest() throws Exception { 221 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 222 mockRecommender.addException(exception); 223 224 try { 225 InsightName name = 226 InsightName.ofProjectLocationInsightTypeInsightName( 227 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]"); 228 client.getInsight(name); 229 Assert.fail("No exception raised"); 230 } catch (InvalidArgumentException e) { 231 // Expected exception. 232 } 233 } 234 235 @Test getInsightTest2()236 public void getInsightTest2() throws Exception { 237 Insight expectedResponse = 238 Insight.newBuilder() 239 .setName( 240 InsightName.ofProjectLocationInsightTypeInsightName( 241 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]") 242 .toString()) 243 .setDescription("description-1724546052") 244 .addAllTargetResources(new ArrayList<String>()) 245 .setInsightSubtype("insightSubtype841535170") 246 .setContent(Struct.newBuilder().build()) 247 .setLastRefreshTime(Timestamp.newBuilder().build()) 248 .setObservationPeriod(Duration.newBuilder().build()) 249 .setStateInfo(InsightStateInfo.newBuilder().build()) 250 .setEtag("etag3123477") 251 .addAllAssociatedRecommendations(new ArrayList<Insight.RecommendationReference>()) 252 .build(); 253 mockRecommender.addResponse(expectedResponse); 254 255 String name = "name3373707"; 256 257 Insight actualResponse = client.getInsight(name); 258 Assert.assertEquals(expectedResponse, actualResponse); 259 260 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 261 Assert.assertEquals(1, actualRequests.size()); 262 GetInsightRequest actualRequest = ((GetInsightRequest) actualRequests.get(0)); 263 264 Assert.assertEquals(name, actualRequest.getName()); 265 Assert.assertTrue( 266 channelProvider.isHeaderSent( 267 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 268 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 269 } 270 271 @Test getInsightExceptionTest2()272 public void getInsightExceptionTest2() throws Exception { 273 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 274 mockRecommender.addException(exception); 275 276 try { 277 String name = "name3373707"; 278 client.getInsight(name); 279 Assert.fail("No exception raised"); 280 } catch (InvalidArgumentException e) { 281 // Expected exception. 282 } 283 } 284 285 @Test markInsightAcceptedTest()286 public void markInsightAcceptedTest() throws Exception { 287 Insight expectedResponse = 288 Insight.newBuilder() 289 .setName( 290 InsightName.ofProjectLocationInsightTypeInsightName( 291 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]") 292 .toString()) 293 .setDescription("description-1724546052") 294 .addAllTargetResources(new ArrayList<String>()) 295 .setInsightSubtype("insightSubtype841535170") 296 .setContent(Struct.newBuilder().build()) 297 .setLastRefreshTime(Timestamp.newBuilder().build()) 298 .setObservationPeriod(Duration.newBuilder().build()) 299 .setStateInfo(InsightStateInfo.newBuilder().build()) 300 .setEtag("etag3123477") 301 .addAllAssociatedRecommendations(new ArrayList<Insight.RecommendationReference>()) 302 .build(); 303 mockRecommender.addResponse(expectedResponse); 304 305 InsightName name = 306 InsightName.ofProjectLocationInsightTypeInsightName( 307 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]"); 308 Map<String, String> stateMetadata = new HashMap<>(); 309 String etag = "etag3123477"; 310 311 Insight actualResponse = client.markInsightAccepted(name, stateMetadata, etag); 312 Assert.assertEquals(expectedResponse, actualResponse); 313 314 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 315 Assert.assertEquals(1, actualRequests.size()); 316 MarkInsightAcceptedRequest actualRequest = ((MarkInsightAcceptedRequest) actualRequests.get(0)); 317 318 Assert.assertEquals(name.toString(), actualRequest.getName()); 319 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 320 Assert.assertEquals(etag, actualRequest.getEtag()); 321 Assert.assertTrue( 322 channelProvider.isHeaderSent( 323 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 324 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 325 } 326 327 @Test markInsightAcceptedExceptionTest()328 public void markInsightAcceptedExceptionTest() throws Exception { 329 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 330 mockRecommender.addException(exception); 331 332 try { 333 InsightName name = 334 InsightName.ofProjectLocationInsightTypeInsightName( 335 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]"); 336 Map<String, String> stateMetadata = new HashMap<>(); 337 String etag = "etag3123477"; 338 client.markInsightAccepted(name, stateMetadata, etag); 339 Assert.fail("No exception raised"); 340 } catch (InvalidArgumentException e) { 341 // Expected exception. 342 } 343 } 344 345 @Test markInsightAcceptedTest2()346 public void markInsightAcceptedTest2() throws Exception { 347 Insight expectedResponse = 348 Insight.newBuilder() 349 .setName( 350 InsightName.ofProjectLocationInsightTypeInsightName( 351 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]", "[INSIGHT]") 352 .toString()) 353 .setDescription("description-1724546052") 354 .addAllTargetResources(new ArrayList<String>()) 355 .setInsightSubtype("insightSubtype841535170") 356 .setContent(Struct.newBuilder().build()) 357 .setLastRefreshTime(Timestamp.newBuilder().build()) 358 .setObservationPeriod(Duration.newBuilder().build()) 359 .setStateInfo(InsightStateInfo.newBuilder().build()) 360 .setEtag("etag3123477") 361 .addAllAssociatedRecommendations(new ArrayList<Insight.RecommendationReference>()) 362 .build(); 363 mockRecommender.addResponse(expectedResponse); 364 365 String name = "name3373707"; 366 Map<String, String> stateMetadata = new HashMap<>(); 367 String etag = "etag3123477"; 368 369 Insight actualResponse = client.markInsightAccepted(name, stateMetadata, etag); 370 Assert.assertEquals(expectedResponse, actualResponse); 371 372 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 373 Assert.assertEquals(1, actualRequests.size()); 374 MarkInsightAcceptedRequest actualRequest = ((MarkInsightAcceptedRequest) actualRequests.get(0)); 375 376 Assert.assertEquals(name, actualRequest.getName()); 377 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 378 Assert.assertEquals(etag, actualRequest.getEtag()); 379 Assert.assertTrue( 380 channelProvider.isHeaderSent( 381 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 382 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 383 } 384 385 @Test markInsightAcceptedExceptionTest2()386 public void markInsightAcceptedExceptionTest2() throws Exception { 387 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 388 mockRecommender.addException(exception); 389 390 try { 391 String name = "name3373707"; 392 Map<String, String> stateMetadata = new HashMap<>(); 393 String etag = "etag3123477"; 394 client.markInsightAccepted(name, stateMetadata, etag); 395 Assert.fail("No exception raised"); 396 } catch (InvalidArgumentException e) { 397 // Expected exception. 398 } 399 } 400 401 @Test listRecommendationsTest()402 public void listRecommendationsTest() throws Exception { 403 Recommendation responsesElement = Recommendation.newBuilder().build(); 404 ListRecommendationsResponse expectedResponse = 405 ListRecommendationsResponse.newBuilder() 406 .setNextPageToken("") 407 .addAllRecommendations(Arrays.asList(responsesElement)) 408 .build(); 409 mockRecommender.addResponse(expectedResponse); 410 411 RecommenderName parent = 412 RecommenderName.ofProjectLocationRecommenderName( 413 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); 414 415 ListRecommendationsPagedResponse pagedListResponse = client.listRecommendations(parent); 416 417 List<Recommendation> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 418 419 Assert.assertEquals(1, resources.size()); 420 Assert.assertEquals(expectedResponse.getRecommendationsList().get(0), resources.get(0)); 421 422 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 423 Assert.assertEquals(1, actualRequests.size()); 424 ListRecommendationsRequest actualRequest = ((ListRecommendationsRequest) actualRequests.get(0)); 425 426 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 427 Assert.assertTrue( 428 channelProvider.isHeaderSent( 429 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 430 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 431 } 432 433 @Test listRecommendationsExceptionTest()434 public void listRecommendationsExceptionTest() throws Exception { 435 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 436 mockRecommender.addException(exception); 437 438 try { 439 RecommenderName parent = 440 RecommenderName.ofProjectLocationRecommenderName( 441 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); 442 client.listRecommendations(parent); 443 Assert.fail("No exception raised"); 444 } catch (InvalidArgumentException e) { 445 // Expected exception. 446 } 447 } 448 449 @Test listRecommendationsTest2()450 public void listRecommendationsTest2() throws Exception { 451 Recommendation responsesElement = Recommendation.newBuilder().build(); 452 ListRecommendationsResponse expectedResponse = 453 ListRecommendationsResponse.newBuilder() 454 .setNextPageToken("") 455 .addAllRecommendations(Arrays.asList(responsesElement)) 456 .build(); 457 mockRecommender.addResponse(expectedResponse); 458 459 String parent = "parent-995424086"; 460 461 ListRecommendationsPagedResponse pagedListResponse = client.listRecommendations(parent); 462 463 List<Recommendation> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 464 465 Assert.assertEquals(1, resources.size()); 466 Assert.assertEquals(expectedResponse.getRecommendationsList().get(0), resources.get(0)); 467 468 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 469 Assert.assertEquals(1, actualRequests.size()); 470 ListRecommendationsRequest actualRequest = ((ListRecommendationsRequest) actualRequests.get(0)); 471 472 Assert.assertEquals(parent, actualRequest.getParent()); 473 Assert.assertTrue( 474 channelProvider.isHeaderSent( 475 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 476 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 477 } 478 479 @Test listRecommendationsExceptionTest2()480 public void listRecommendationsExceptionTest2() throws Exception { 481 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 482 mockRecommender.addException(exception); 483 484 try { 485 String parent = "parent-995424086"; 486 client.listRecommendations(parent); 487 Assert.fail("No exception raised"); 488 } catch (InvalidArgumentException e) { 489 // Expected exception. 490 } 491 } 492 493 @Test listRecommendationsTest3()494 public void listRecommendationsTest3() throws Exception { 495 Recommendation responsesElement = Recommendation.newBuilder().build(); 496 ListRecommendationsResponse expectedResponse = 497 ListRecommendationsResponse.newBuilder() 498 .setNextPageToken("") 499 .addAllRecommendations(Arrays.asList(responsesElement)) 500 .build(); 501 mockRecommender.addResponse(expectedResponse); 502 503 RecommenderName parent = 504 RecommenderName.ofProjectLocationRecommenderName( 505 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); 506 String filter = "filter-1274492040"; 507 508 ListRecommendationsPagedResponse pagedListResponse = client.listRecommendations(parent, filter); 509 510 List<Recommendation> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 511 512 Assert.assertEquals(1, resources.size()); 513 Assert.assertEquals(expectedResponse.getRecommendationsList().get(0), resources.get(0)); 514 515 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 516 Assert.assertEquals(1, actualRequests.size()); 517 ListRecommendationsRequest actualRequest = ((ListRecommendationsRequest) actualRequests.get(0)); 518 519 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 520 Assert.assertEquals(filter, actualRequest.getFilter()); 521 Assert.assertTrue( 522 channelProvider.isHeaderSent( 523 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 524 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 525 } 526 527 @Test listRecommendationsExceptionTest3()528 public void listRecommendationsExceptionTest3() throws Exception { 529 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 530 mockRecommender.addException(exception); 531 532 try { 533 RecommenderName parent = 534 RecommenderName.ofProjectLocationRecommenderName( 535 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); 536 String filter = "filter-1274492040"; 537 client.listRecommendations(parent, filter); 538 Assert.fail("No exception raised"); 539 } catch (InvalidArgumentException e) { 540 // Expected exception. 541 } 542 } 543 544 @Test listRecommendationsTest4()545 public void listRecommendationsTest4() throws Exception { 546 Recommendation responsesElement = Recommendation.newBuilder().build(); 547 ListRecommendationsResponse expectedResponse = 548 ListRecommendationsResponse.newBuilder() 549 .setNextPageToken("") 550 .addAllRecommendations(Arrays.asList(responsesElement)) 551 .build(); 552 mockRecommender.addResponse(expectedResponse); 553 554 String parent = "parent-995424086"; 555 String filter = "filter-1274492040"; 556 557 ListRecommendationsPagedResponse pagedListResponse = client.listRecommendations(parent, filter); 558 559 List<Recommendation> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 560 561 Assert.assertEquals(1, resources.size()); 562 Assert.assertEquals(expectedResponse.getRecommendationsList().get(0), resources.get(0)); 563 564 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 565 Assert.assertEquals(1, actualRequests.size()); 566 ListRecommendationsRequest actualRequest = ((ListRecommendationsRequest) actualRequests.get(0)); 567 568 Assert.assertEquals(parent, actualRequest.getParent()); 569 Assert.assertEquals(filter, actualRequest.getFilter()); 570 Assert.assertTrue( 571 channelProvider.isHeaderSent( 572 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 573 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 574 } 575 576 @Test listRecommendationsExceptionTest4()577 public void listRecommendationsExceptionTest4() throws Exception { 578 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 579 mockRecommender.addException(exception); 580 581 try { 582 String parent = "parent-995424086"; 583 String filter = "filter-1274492040"; 584 client.listRecommendations(parent, filter); 585 Assert.fail("No exception raised"); 586 } catch (InvalidArgumentException e) { 587 // Expected exception. 588 } 589 } 590 591 @Test getRecommendationTest()592 public void getRecommendationTest() throws Exception { 593 Recommendation expectedResponse = 594 Recommendation.newBuilder() 595 .setName( 596 RecommendationName.ofProjectLocationRecommenderRecommendationName( 597 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 598 .toString()) 599 .setDescription("description-1724546052") 600 .setRecommenderSubtype("recommenderSubtype1811451601") 601 .setLastRefreshTime(Timestamp.newBuilder().build()) 602 .setPrimaryImpact(Impact.newBuilder().build()) 603 .addAllAdditionalImpact(new ArrayList<Impact>()) 604 .setContent(RecommendationContent.newBuilder().build()) 605 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 606 .setEtag("etag3123477") 607 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 608 .setXorGroupId("xorGroupId-2095769825") 609 .build(); 610 mockRecommender.addResponse(expectedResponse); 611 612 RecommendationName name = 613 RecommendationName.ofProjectLocationRecommenderRecommendationName( 614 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 615 616 Recommendation actualResponse = client.getRecommendation(name); 617 Assert.assertEquals(expectedResponse, actualResponse); 618 619 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 620 Assert.assertEquals(1, actualRequests.size()); 621 GetRecommendationRequest actualRequest = ((GetRecommendationRequest) actualRequests.get(0)); 622 623 Assert.assertEquals(name.toString(), actualRequest.getName()); 624 Assert.assertTrue( 625 channelProvider.isHeaderSent( 626 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 627 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 628 } 629 630 @Test getRecommendationExceptionTest()631 public void getRecommendationExceptionTest() throws Exception { 632 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 633 mockRecommender.addException(exception); 634 635 try { 636 RecommendationName name = 637 RecommendationName.ofProjectLocationRecommenderRecommendationName( 638 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 639 client.getRecommendation(name); 640 Assert.fail("No exception raised"); 641 } catch (InvalidArgumentException e) { 642 // Expected exception. 643 } 644 } 645 646 @Test getRecommendationTest2()647 public void getRecommendationTest2() throws Exception { 648 Recommendation expectedResponse = 649 Recommendation.newBuilder() 650 .setName( 651 RecommendationName.ofProjectLocationRecommenderRecommendationName( 652 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 653 .toString()) 654 .setDescription("description-1724546052") 655 .setRecommenderSubtype("recommenderSubtype1811451601") 656 .setLastRefreshTime(Timestamp.newBuilder().build()) 657 .setPrimaryImpact(Impact.newBuilder().build()) 658 .addAllAdditionalImpact(new ArrayList<Impact>()) 659 .setContent(RecommendationContent.newBuilder().build()) 660 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 661 .setEtag("etag3123477") 662 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 663 .setXorGroupId("xorGroupId-2095769825") 664 .build(); 665 mockRecommender.addResponse(expectedResponse); 666 667 String name = "name3373707"; 668 669 Recommendation actualResponse = client.getRecommendation(name); 670 Assert.assertEquals(expectedResponse, actualResponse); 671 672 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 673 Assert.assertEquals(1, actualRequests.size()); 674 GetRecommendationRequest actualRequest = ((GetRecommendationRequest) actualRequests.get(0)); 675 676 Assert.assertEquals(name, actualRequest.getName()); 677 Assert.assertTrue( 678 channelProvider.isHeaderSent( 679 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 680 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 681 } 682 683 @Test getRecommendationExceptionTest2()684 public void getRecommendationExceptionTest2() throws Exception { 685 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 686 mockRecommender.addException(exception); 687 688 try { 689 String name = "name3373707"; 690 client.getRecommendation(name); 691 Assert.fail("No exception raised"); 692 } catch (InvalidArgumentException e) { 693 // Expected exception. 694 } 695 } 696 697 @Test markRecommendationClaimedTest()698 public void markRecommendationClaimedTest() throws Exception { 699 Recommendation expectedResponse = 700 Recommendation.newBuilder() 701 .setName( 702 RecommendationName.ofProjectLocationRecommenderRecommendationName( 703 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 704 .toString()) 705 .setDescription("description-1724546052") 706 .setRecommenderSubtype("recommenderSubtype1811451601") 707 .setLastRefreshTime(Timestamp.newBuilder().build()) 708 .setPrimaryImpact(Impact.newBuilder().build()) 709 .addAllAdditionalImpact(new ArrayList<Impact>()) 710 .setContent(RecommendationContent.newBuilder().build()) 711 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 712 .setEtag("etag3123477") 713 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 714 .setXorGroupId("xorGroupId-2095769825") 715 .build(); 716 mockRecommender.addResponse(expectedResponse); 717 718 RecommendationName name = 719 RecommendationName.ofProjectLocationRecommenderRecommendationName( 720 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 721 Map<String, String> stateMetadata = new HashMap<>(); 722 String etag = "etag3123477"; 723 724 Recommendation actualResponse = client.markRecommendationClaimed(name, stateMetadata, etag); 725 Assert.assertEquals(expectedResponse, actualResponse); 726 727 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 728 Assert.assertEquals(1, actualRequests.size()); 729 MarkRecommendationClaimedRequest actualRequest = 730 ((MarkRecommendationClaimedRequest) actualRequests.get(0)); 731 732 Assert.assertEquals(name.toString(), actualRequest.getName()); 733 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 734 Assert.assertEquals(etag, actualRequest.getEtag()); 735 Assert.assertTrue( 736 channelProvider.isHeaderSent( 737 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 738 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 739 } 740 741 @Test markRecommendationClaimedExceptionTest()742 public void markRecommendationClaimedExceptionTest() throws Exception { 743 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 744 mockRecommender.addException(exception); 745 746 try { 747 RecommendationName name = 748 RecommendationName.ofProjectLocationRecommenderRecommendationName( 749 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 750 Map<String, String> stateMetadata = new HashMap<>(); 751 String etag = "etag3123477"; 752 client.markRecommendationClaimed(name, stateMetadata, etag); 753 Assert.fail("No exception raised"); 754 } catch (InvalidArgumentException e) { 755 // Expected exception. 756 } 757 } 758 759 @Test markRecommendationClaimedTest2()760 public void markRecommendationClaimedTest2() throws Exception { 761 Recommendation expectedResponse = 762 Recommendation.newBuilder() 763 .setName( 764 RecommendationName.ofProjectLocationRecommenderRecommendationName( 765 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 766 .toString()) 767 .setDescription("description-1724546052") 768 .setRecommenderSubtype("recommenderSubtype1811451601") 769 .setLastRefreshTime(Timestamp.newBuilder().build()) 770 .setPrimaryImpact(Impact.newBuilder().build()) 771 .addAllAdditionalImpact(new ArrayList<Impact>()) 772 .setContent(RecommendationContent.newBuilder().build()) 773 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 774 .setEtag("etag3123477") 775 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 776 .setXorGroupId("xorGroupId-2095769825") 777 .build(); 778 mockRecommender.addResponse(expectedResponse); 779 780 String name = "name3373707"; 781 Map<String, String> stateMetadata = new HashMap<>(); 782 String etag = "etag3123477"; 783 784 Recommendation actualResponse = client.markRecommendationClaimed(name, stateMetadata, etag); 785 Assert.assertEquals(expectedResponse, actualResponse); 786 787 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 788 Assert.assertEquals(1, actualRequests.size()); 789 MarkRecommendationClaimedRequest actualRequest = 790 ((MarkRecommendationClaimedRequest) actualRequests.get(0)); 791 792 Assert.assertEquals(name, actualRequest.getName()); 793 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 794 Assert.assertEquals(etag, actualRequest.getEtag()); 795 Assert.assertTrue( 796 channelProvider.isHeaderSent( 797 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 798 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 799 } 800 801 @Test markRecommendationClaimedExceptionTest2()802 public void markRecommendationClaimedExceptionTest2() throws Exception { 803 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 804 mockRecommender.addException(exception); 805 806 try { 807 String name = "name3373707"; 808 Map<String, String> stateMetadata = new HashMap<>(); 809 String etag = "etag3123477"; 810 client.markRecommendationClaimed(name, stateMetadata, etag); 811 Assert.fail("No exception raised"); 812 } catch (InvalidArgumentException e) { 813 // Expected exception. 814 } 815 } 816 817 @Test markRecommendationSucceededTest()818 public void markRecommendationSucceededTest() throws Exception { 819 Recommendation expectedResponse = 820 Recommendation.newBuilder() 821 .setName( 822 RecommendationName.ofProjectLocationRecommenderRecommendationName( 823 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 824 .toString()) 825 .setDescription("description-1724546052") 826 .setRecommenderSubtype("recommenderSubtype1811451601") 827 .setLastRefreshTime(Timestamp.newBuilder().build()) 828 .setPrimaryImpact(Impact.newBuilder().build()) 829 .addAllAdditionalImpact(new ArrayList<Impact>()) 830 .setContent(RecommendationContent.newBuilder().build()) 831 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 832 .setEtag("etag3123477") 833 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 834 .setXorGroupId("xorGroupId-2095769825") 835 .build(); 836 mockRecommender.addResponse(expectedResponse); 837 838 RecommendationName name = 839 RecommendationName.ofProjectLocationRecommenderRecommendationName( 840 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 841 Map<String, String> stateMetadata = new HashMap<>(); 842 String etag = "etag3123477"; 843 844 Recommendation actualResponse = client.markRecommendationSucceeded(name, stateMetadata, etag); 845 Assert.assertEquals(expectedResponse, actualResponse); 846 847 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 848 Assert.assertEquals(1, actualRequests.size()); 849 MarkRecommendationSucceededRequest actualRequest = 850 ((MarkRecommendationSucceededRequest) actualRequests.get(0)); 851 852 Assert.assertEquals(name.toString(), actualRequest.getName()); 853 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 854 Assert.assertEquals(etag, actualRequest.getEtag()); 855 Assert.assertTrue( 856 channelProvider.isHeaderSent( 857 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 858 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 859 } 860 861 @Test markRecommendationSucceededExceptionTest()862 public void markRecommendationSucceededExceptionTest() throws Exception { 863 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 864 mockRecommender.addException(exception); 865 866 try { 867 RecommendationName name = 868 RecommendationName.ofProjectLocationRecommenderRecommendationName( 869 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 870 Map<String, String> stateMetadata = new HashMap<>(); 871 String etag = "etag3123477"; 872 client.markRecommendationSucceeded(name, stateMetadata, etag); 873 Assert.fail("No exception raised"); 874 } catch (InvalidArgumentException e) { 875 // Expected exception. 876 } 877 } 878 879 @Test markRecommendationSucceededTest2()880 public void markRecommendationSucceededTest2() throws Exception { 881 Recommendation expectedResponse = 882 Recommendation.newBuilder() 883 .setName( 884 RecommendationName.ofProjectLocationRecommenderRecommendationName( 885 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 886 .toString()) 887 .setDescription("description-1724546052") 888 .setRecommenderSubtype("recommenderSubtype1811451601") 889 .setLastRefreshTime(Timestamp.newBuilder().build()) 890 .setPrimaryImpact(Impact.newBuilder().build()) 891 .addAllAdditionalImpact(new ArrayList<Impact>()) 892 .setContent(RecommendationContent.newBuilder().build()) 893 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 894 .setEtag("etag3123477") 895 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 896 .setXorGroupId("xorGroupId-2095769825") 897 .build(); 898 mockRecommender.addResponse(expectedResponse); 899 900 String name = "name3373707"; 901 Map<String, String> stateMetadata = new HashMap<>(); 902 String etag = "etag3123477"; 903 904 Recommendation actualResponse = client.markRecommendationSucceeded(name, stateMetadata, etag); 905 Assert.assertEquals(expectedResponse, actualResponse); 906 907 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 908 Assert.assertEquals(1, actualRequests.size()); 909 MarkRecommendationSucceededRequest actualRequest = 910 ((MarkRecommendationSucceededRequest) actualRequests.get(0)); 911 912 Assert.assertEquals(name, actualRequest.getName()); 913 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 914 Assert.assertEquals(etag, actualRequest.getEtag()); 915 Assert.assertTrue( 916 channelProvider.isHeaderSent( 917 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 918 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 919 } 920 921 @Test markRecommendationSucceededExceptionTest2()922 public void markRecommendationSucceededExceptionTest2() throws Exception { 923 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 924 mockRecommender.addException(exception); 925 926 try { 927 String name = "name3373707"; 928 Map<String, String> stateMetadata = new HashMap<>(); 929 String etag = "etag3123477"; 930 client.markRecommendationSucceeded(name, stateMetadata, etag); 931 Assert.fail("No exception raised"); 932 } catch (InvalidArgumentException e) { 933 // Expected exception. 934 } 935 } 936 937 @Test markRecommendationFailedTest()938 public void markRecommendationFailedTest() throws Exception { 939 Recommendation expectedResponse = 940 Recommendation.newBuilder() 941 .setName( 942 RecommendationName.ofProjectLocationRecommenderRecommendationName( 943 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 944 .toString()) 945 .setDescription("description-1724546052") 946 .setRecommenderSubtype("recommenderSubtype1811451601") 947 .setLastRefreshTime(Timestamp.newBuilder().build()) 948 .setPrimaryImpact(Impact.newBuilder().build()) 949 .addAllAdditionalImpact(new ArrayList<Impact>()) 950 .setContent(RecommendationContent.newBuilder().build()) 951 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 952 .setEtag("etag3123477") 953 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 954 .setXorGroupId("xorGroupId-2095769825") 955 .build(); 956 mockRecommender.addResponse(expectedResponse); 957 958 RecommendationName name = 959 RecommendationName.ofProjectLocationRecommenderRecommendationName( 960 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 961 Map<String, String> stateMetadata = new HashMap<>(); 962 String etag = "etag3123477"; 963 964 Recommendation actualResponse = client.markRecommendationFailed(name, stateMetadata, etag); 965 Assert.assertEquals(expectedResponse, actualResponse); 966 967 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 968 Assert.assertEquals(1, actualRequests.size()); 969 MarkRecommendationFailedRequest actualRequest = 970 ((MarkRecommendationFailedRequest) actualRequests.get(0)); 971 972 Assert.assertEquals(name.toString(), actualRequest.getName()); 973 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 974 Assert.assertEquals(etag, actualRequest.getEtag()); 975 Assert.assertTrue( 976 channelProvider.isHeaderSent( 977 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 978 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 979 } 980 981 @Test markRecommendationFailedExceptionTest()982 public void markRecommendationFailedExceptionTest() throws Exception { 983 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 984 mockRecommender.addException(exception); 985 986 try { 987 RecommendationName name = 988 RecommendationName.ofProjectLocationRecommenderRecommendationName( 989 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]"); 990 Map<String, String> stateMetadata = new HashMap<>(); 991 String etag = "etag3123477"; 992 client.markRecommendationFailed(name, stateMetadata, etag); 993 Assert.fail("No exception raised"); 994 } catch (InvalidArgumentException e) { 995 // Expected exception. 996 } 997 } 998 999 @Test markRecommendationFailedTest2()1000 public void markRecommendationFailedTest2() throws Exception { 1001 Recommendation expectedResponse = 1002 Recommendation.newBuilder() 1003 .setName( 1004 RecommendationName.ofProjectLocationRecommenderRecommendationName( 1005 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]", "[RECOMMENDATION]") 1006 .toString()) 1007 .setDescription("description-1724546052") 1008 .setRecommenderSubtype("recommenderSubtype1811451601") 1009 .setLastRefreshTime(Timestamp.newBuilder().build()) 1010 .setPrimaryImpact(Impact.newBuilder().build()) 1011 .addAllAdditionalImpact(new ArrayList<Impact>()) 1012 .setContent(RecommendationContent.newBuilder().build()) 1013 .setStateInfo(RecommendationStateInfo.newBuilder().build()) 1014 .setEtag("etag3123477") 1015 .addAllAssociatedInsights(new ArrayList<Recommendation.InsightReference>()) 1016 .setXorGroupId("xorGroupId-2095769825") 1017 .build(); 1018 mockRecommender.addResponse(expectedResponse); 1019 1020 String name = "name3373707"; 1021 Map<String, String> stateMetadata = new HashMap<>(); 1022 String etag = "etag3123477"; 1023 1024 Recommendation actualResponse = client.markRecommendationFailed(name, stateMetadata, etag); 1025 Assert.assertEquals(expectedResponse, actualResponse); 1026 1027 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1028 Assert.assertEquals(1, actualRequests.size()); 1029 MarkRecommendationFailedRequest actualRequest = 1030 ((MarkRecommendationFailedRequest) actualRequests.get(0)); 1031 1032 Assert.assertEquals(name, actualRequest.getName()); 1033 Assert.assertEquals(stateMetadata, actualRequest.getStateMetadataMap()); 1034 Assert.assertEquals(etag, actualRequest.getEtag()); 1035 Assert.assertTrue( 1036 channelProvider.isHeaderSent( 1037 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1038 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1039 } 1040 1041 @Test markRecommendationFailedExceptionTest2()1042 public void markRecommendationFailedExceptionTest2() throws Exception { 1043 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1044 mockRecommender.addException(exception); 1045 1046 try { 1047 String name = "name3373707"; 1048 Map<String, String> stateMetadata = new HashMap<>(); 1049 String etag = "etag3123477"; 1050 client.markRecommendationFailed(name, stateMetadata, etag); 1051 Assert.fail("No exception raised"); 1052 } catch (InvalidArgumentException e) { 1053 // Expected exception. 1054 } 1055 } 1056 1057 @Test getRecommenderConfigTest()1058 public void getRecommenderConfigTest() throws Exception { 1059 RecommenderConfig expectedResponse = 1060 RecommenderConfig.newBuilder() 1061 .setName( 1062 RecommenderConfigName.ofProjectLocationRecommenderName( 1063 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]") 1064 .toString()) 1065 .setRecommenderGenerationConfig(RecommenderGenerationConfig.newBuilder().build()) 1066 .setEtag("etag3123477") 1067 .setUpdateTime(Timestamp.newBuilder().build()) 1068 .setRevisionId("revisionId-1507445162") 1069 .putAllAnnotations(new HashMap<String, String>()) 1070 .setDisplayName("displayName1714148973") 1071 .build(); 1072 mockRecommender.addResponse(expectedResponse); 1073 1074 RecommenderConfigName name = 1075 RecommenderConfigName.ofProjectLocationRecommenderName( 1076 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); 1077 1078 RecommenderConfig actualResponse = client.getRecommenderConfig(name); 1079 Assert.assertEquals(expectedResponse, actualResponse); 1080 1081 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1082 Assert.assertEquals(1, actualRequests.size()); 1083 GetRecommenderConfigRequest actualRequest = 1084 ((GetRecommenderConfigRequest) actualRequests.get(0)); 1085 1086 Assert.assertEquals(name.toString(), actualRequest.getName()); 1087 Assert.assertTrue( 1088 channelProvider.isHeaderSent( 1089 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1090 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1091 } 1092 1093 @Test getRecommenderConfigExceptionTest()1094 public void getRecommenderConfigExceptionTest() throws Exception { 1095 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1096 mockRecommender.addException(exception); 1097 1098 try { 1099 RecommenderConfigName name = 1100 RecommenderConfigName.ofProjectLocationRecommenderName( 1101 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]"); 1102 client.getRecommenderConfig(name); 1103 Assert.fail("No exception raised"); 1104 } catch (InvalidArgumentException e) { 1105 // Expected exception. 1106 } 1107 } 1108 1109 @Test getRecommenderConfigTest2()1110 public void getRecommenderConfigTest2() throws Exception { 1111 RecommenderConfig expectedResponse = 1112 RecommenderConfig.newBuilder() 1113 .setName( 1114 RecommenderConfigName.ofProjectLocationRecommenderName( 1115 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]") 1116 .toString()) 1117 .setRecommenderGenerationConfig(RecommenderGenerationConfig.newBuilder().build()) 1118 .setEtag("etag3123477") 1119 .setUpdateTime(Timestamp.newBuilder().build()) 1120 .setRevisionId("revisionId-1507445162") 1121 .putAllAnnotations(new HashMap<String, String>()) 1122 .setDisplayName("displayName1714148973") 1123 .build(); 1124 mockRecommender.addResponse(expectedResponse); 1125 1126 String name = "name3373707"; 1127 1128 RecommenderConfig actualResponse = client.getRecommenderConfig(name); 1129 Assert.assertEquals(expectedResponse, actualResponse); 1130 1131 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1132 Assert.assertEquals(1, actualRequests.size()); 1133 GetRecommenderConfigRequest actualRequest = 1134 ((GetRecommenderConfigRequest) actualRequests.get(0)); 1135 1136 Assert.assertEquals(name, actualRequest.getName()); 1137 Assert.assertTrue( 1138 channelProvider.isHeaderSent( 1139 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1140 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1141 } 1142 1143 @Test getRecommenderConfigExceptionTest2()1144 public void getRecommenderConfigExceptionTest2() throws Exception { 1145 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1146 mockRecommender.addException(exception); 1147 1148 try { 1149 String name = "name3373707"; 1150 client.getRecommenderConfig(name); 1151 Assert.fail("No exception raised"); 1152 } catch (InvalidArgumentException e) { 1153 // Expected exception. 1154 } 1155 } 1156 1157 @Test updateRecommenderConfigTest()1158 public void updateRecommenderConfigTest() throws Exception { 1159 RecommenderConfig expectedResponse = 1160 RecommenderConfig.newBuilder() 1161 .setName( 1162 RecommenderConfigName.ofProjectLocationRecommenderName( 1163 "[PROJECT]", "[LOCATION]", "[RECOMMENDER]") 1164 .toString()) 1165 .setRecommenderGenerationConfig(RecommenderGenerationConfig.newBuilder().build()) 1166 .setEtag("etag3123477") 1167 .setUpdateTime(Timestamp.newBuilder().build()) 1168 .setRevisionId("revisionId-1507445162") 1169 .putAllAnnotations(new HashMap<String, String>()) 1170 .setDisplayName("displayName1714148973") 1171 .build(); 1172 mockRecommender.addResponse(expectedResponse); 1173 1174 RecommenderConfig recommenderConfig = RecommenderConfig.newBuilder().build(); 1175 FieldMask updateMask = FieldMask.newBuilder().build(); 1176 1177 RecommenderConfig actualResponse = 1178 client.updateRecommenderConfig(recommenderConfig, updateMask); 1179 Assert.assertEquals(expectedResponse, actualResponse); 1180 1181 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1182 Assert.assertEquals(1, actualRequests.size()); 1183 UpdateRecommenderConfigRequest actualRequest = 1184 ((UpdateRecommenderConfigRequest) actualRequests.get(0)); 1185 1186 Assert.assertEquals(recommenderConfig, actualRequest.getRecommenderConfig()); 1187 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 1188 Assert.assertTrue( 1189 channelProvider.isHeaderSent( 1190 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1191 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1192 } 1193 1194 @Test updateRecommenderConfigExceptionTest()1195 public void updateRecommenderConfigExceptionTest() throws Exception { 1196 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1197 mockRecommender.addException(exception); 1198 1199 try { 1200 RecommenderConfig recommenderConfig = RecommenderConfig.newBuilder().build(); 1201 FieldMask updateMask = FieldMask.newBuilder().build(); 1202 client.updateRecommenderConfig(recommenderConfig, updateMask); 1203 Assert.fail("No exception raised"); 1204 } catch (InvalidArgumentException e) { 1205 // Expected exception. 1206 } 1207 } 1208 1209 @Test getInsightTypeConfigTest()1210 public void getInsightTypeConfigTest() throws Exception { 1211 InsightTypeConfig expectedResponse = 1212 InsightTypeConfig.newBuilder() 1213 .setName( 1214 InsightTypeConfigName.ofProjectLocationInsightTypeName( 1215 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]") 1216 .toString()) 1217 .setInsightTypeGenerationConfig(InsightTypeGenerationConfig.newBuilder().build()) 1218 .setEtag("etag3123477") 1219 .setUpdateTime(Timestamp.newBuilder().build()) 1220 .setRevisionId("revisionId-1507445162") 1221 .putAllAnnotations(new HashMap<String, String>()) 1222 .setDisplayName("displayName1714148973") 1223 .build(); 1224 mockRecommender.addResponse(expectedResponse); 1225 1226 InsightTypeConfigName name = 1227 InsightTypeConfigName.ofProjectLocationInsightTypeName( 1228 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]"); 1229 1230 InsightTypeConfig actualResponse = client.getInsightTypeConfig(name); 1231 Assert.assertEquals(expectedResponse, actualResponse); 1232 1233 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1234 Assert.assertEquals(1, actualRequests.size()); 1235 GetInsightTypeConfigRequest actualRequest = 1236 ((GetInsightTypeConfigRequest) actualRequests.get(0)); 1237 1238 Assert.assertEquals(name.toString(), actualRequest.getName()); 1239 Assert.assertTrue( 1240 channelProvider.isHeaderSent( 1241 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1242 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1243 } 1244 1245 @Test getInsightTypeConfigExceptionTest()1246 public void getInsightTypeConfigExceptionTest() throws Exception { 1247 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1248 mockRecommender.addException(exception); 1249 1250 try { 1251 InsightTypeConfigName name = 1252 InsightTypeConfigName.ofProjectLocationInsightTypeName( 1253 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]"); 1254 client.getInsightTypeConfig(name); 1255 Assert.fail("No exception raised"); 1256 } catch (InvalidArgumentException e) { 1257 // Expected exception. 1258 } 1259 } 1260 1261 @Test getInsightTypeConfigTest2()1262 public void getInsightTypeConfigTest2() throws Exception { 1263 InsightTypeConfig expectedResponse = 1264 InsightTypeConfig.newBuilder() 1265 .setName( 1266 InsightTypeConfigName.ofProjectLocationInsightTypeName( 1267 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]") 1268 .toString()) 1269 .setInsightTypeGenerationConfig(InsightTypeGenerationConfig.newBuilder().build()) 1270 .setEtag("etag3123477") 1271 .setUpdateTime(Timestamp.newBuilder().build()) 1272 .setRevisionId("revisionId-1507445162") 1273 .putAllAnnotations(new HashMap<String, String>()) 1274 .setDisplayName("displayName1714148973") 1275 .build(); 1276 mockRecommender.addResponse(expectedResponse); 1277 1278 String name = "name3373707"; 1279 1280 InsightTypeConfig actualResponse = client.getInsightTypeConfig(name); 1281 Assert.assertEquals(expectedResponse, actualResponse); 1282 1283 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1284 Assert.assertEquals(1, actualRequests.size()); 1285 GetInsightTypeConfigRequest actualRequest = 1286 ((GetInsightTypeConfigRequest) actualRequests.get(0)); 1287 1288 Assert.assertEquals(name, actualRequest.getName()); 1289 Assert.assertTrue( 1290 channelProvider.isHeaderSent( 1291 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1292 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1293 } 1294 1295 @Test getInsightTypeConfigExceptionTest2()1296 public void getInsightTypeConfigExceptionTest2() throws Exception { 1297 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1298 mockRecommender.addException(exception); 1299 1300 try { 1301 String name = "name3373707"; 1302 client.getInsightTypeConfig(name); 1303 Assert.fail("No exception raised"); 1304 } catch (InvalidArgumentException e) { 1305 // Expected exception. 1306 } 1307 } 1308 1309 @Test updateInsightTypeConfigTest()1310 public void updateInsightTypeConfigTest() throws Exception { 1311 InsightTypeConfig expectedResponse = 1312 InsightTypeConfig.newBuilder() 1313 .setName( 1314 InsightTypeConfigName.ofProjectLocationInsightTypeName( 1315 "[PROJECT]", "[LOCATION]", "[INSIGHT_TYPE]") 1316 .toString()) 1317 .setInsightTypeGenerationConfig(InsightTypeGenerationConfig.newBuilder().build()) 1318 .setEtag("etag3123477") 1319 .setUpdateTime(Timestamp.newBuilder().build()) 1320 .setRevisionId("revisionId-1507445162") 1321 .putAllAnnotations(new HashMap<String, String>()) 1322 .setDisplayName("displayName1714148973") 1323 .build(); 1324 mockRecommender.addResponse(expectedResponse); 1325 1326 InsightTypeConfig insightTypeConfig = InsightTypeConfig.newBuilder().build(); 1327 FieldMask updateMask = FieldMask.newBuilder().build(); 1328 1329 InsightTypeConfig actualResponse = 1330 client.updateInsightTypeConfig(insightTypeConfig, updateMask); 1331 Assert.assertEquals(expectedResponse, actualResponse); 1332 1333 List<AbstractMessage> actualRequests = mockRecommender.getRequests(); 1334 Assert.assertEquals(1, actualRequests.size()); 1335 UpdateInsightTypeConfigRequest actualRequest = 1336 ((UpdateInsightTypeConfigRequest) actualRequests.get(0)); 1337 1338 Assert.assertEquals(insightTypeConfig, actualRequest.getInsightTypeConfig()); 1339 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 1340 Assert.assertTrue( 1341 channelProvider.isHeaderSent( 1342 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1343 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1344 } 1345 1346 @Test updateInsightTypeConfigExceptionTest()1347 public void updateInsightTypeConfigExceptionTest() throws Exception { 1348 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1349 mockRecommender.addException(exception); 1350 1351 try { 1352 InsightTypeConfig insightTypeConfig = InsightTypeConfig.newBuilder().build(); 1353 FieldMask updateMask = FieldMask.newBuilder().build(); 1354 client.updateInsightTypeConfig(insightTypeConfig, updateMask); 1355 Assert.fail("No exception raised"); 1356 } catch (InvalidArgumentException e) { 1357 // Expected exception. 1358 } 1359 } 1360 } 1361