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.retail.v2beta; 18 19 import static com.google.cloud.retail.v2beta.ProductServiceClient.ListProductsPagedResponse; 20 21 import com.google.api.gax.core.NoCredentialsProvider; 22 import com.google.api.gax.grpc.GaxGrpcProperties; 23 import com.google.api.gax.grpc.testing.LocalChannelProvider; 24 import com.google.api.gax.grpc.testing.MockGrpcService; 25 import com.google.api.gax.grpc.testing.MockServiceHelper; 26 import com.google.api.gax.rpc.ApiClientHeaderProvider; 27 import com.google.api.gax.rpc.InvalidArgumentException; 28 import com.google.api.gax.rpc.StatusCode; 29 import com.google.common.collect.Lists; 30 import com.google.longrunning.Operation; 31 import com.google.protobuf.AbstractMessage; 32 import com.google.protobuf.Any; 33 import com.google.protobuf.Empty; 34 import com.google.protobuf.FieldMask; 35 import com.google.protobuf.Int32Value; 36 import com.google.protobuf.Timestamp; 37 import com.google.rpc.Status; 38 import io.grpc.StatusRuntimeException; 39 import java.io.IOException; 40 import java.util.ArrayList; 41 import java.util.Arrays; 42 import java.util.HashMap; 43 import java.util.List; 44 import java.util.UUID; 45 import java.util.concurrent.ExecutionException; 46 import javax.annotation.Generated; 47 import org.junit.After; 48 import org.junit.AfterClass; 49 import org.junit.Assert; 50 import org.junit.Before; 51 import org.junit.BeforeClass; 52 import org.junit.Test; 53 54 @Generated("by gapic-generator-java") 55 public class ProductServiceClientTest { 56 private static MockProductService mockProductService; 57 private static MockServiceHelper mockServiceHelper; 58 private LocalChannelProvider channelProvider; 59 private ProductServiceClient client; 60 61 @BeforeClass startStaticServer()62 public static void startStaticServer() { 63 mockProductService = new MockProductService(); 64 mockServiceHelper = 65 new MockServiceHelper( 66 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockProductService)); 67 mockServiceHelper.start(); 68 } 69 70 @AfterClass stopServer()71 public static void stopServer() { 72 mockServiceHelper.stop(); 73 } 74 75 @Before setUp()76 public void setUp() throws IOException { 77 mockServiceHelper.reset(); 78 channelProvider = mockServiceHelper.createChannelProvider(); 79 ProductServiceSettings settings = 80 ProductServiceSettings.newBuilder() 81 .setTransportChannelProvider(channelProvider) 82 .setCredentialsProvider(NoCredentialsProvider.create()) 83 .build(); 84 client = ProductServiceClient.create(settings); 85 } 86 87 @After tearDown()88 public void tearDown() throws Exception { 89 client.close(); 90 } 91 92 @Test createProductTest()93 public void createProductTest() throws Exception { 94 Product expectedResponse = 95 Product.newBuilder() 96 .setName( 97 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]") 98 .toString()) 99 .setId("id3355") 100 .setPrimaryProductId("primaryProductId-857339256") 101 .addAllCollectionMemberIds(new ArrayList<String>()) 102 .setGtin("gtin3183314") 103 .addAllCategories(new ArrayList<String>()) 104 .setTitle("title110371416") 105 .addAllBrands(new ArrayList<String>()) 106 .setDescription("description-1724546052") 107 .setLanguageCode("languageCode-2092349083") 108 .putAllAttributes(new HashMap<String, CustomAttribute>()) 109 .addAllTags(new ArrayList<String>()) 110 .setPriceInfo(PriceInfo.newBuilder().build()) 111 .setRating(Rating.newBuilder().build()) 112 .setAvailableTime(Timestamp.newBuilder().build()) 113 .setAvailableQuantity(Int32Value.newBuilder().build()) 114 .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>()) 115 .setUri("uri116076") 116 .addAllImages(new ArrayList<Image>()) 117 .setAudience(Audience.newBuilder().build()) 118 .setColorInfo(ColorInfo.newBuilder().build()) 119 .addAllSizes(new ArrayList<String>()) 120 .addAllMaterials(new ArrayList<String>()) 121 .addAllPatterns(new ArrayList<String>()) 122 .addAllConditions(new ArrayList<String>()) 123 .addAllPromotions(new ArrayList<Promotion>()) 124 .setPublishTime(Timestamp.newBuilder().build()) 125 .setRetrievableFields(FieldMask.newBuilder().build()) 126 .addAllVariants(new ArrayList<Product>()) 127 .addAllLocalInventories(new ArrayList<LocalInventory>()) 128 .build(); 129 mockProductService.addResponse(expectedResponse); 130 131 BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]"); 132 Product product = Product.newBuilder().build(); 133 String productId = "productId-1051830678"; 134 135 Product actualResponse = client.createProduct(parent, product, productId); 136 Assert.assertEquals(expectedResponse, actualResponse); 137 138 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 139 Assert.assertEquals(1, actualRequests.size()); 140 CreateProductRequest actualRequest = ((CreateProductRequest) actualRequests.get(0)); 141 142 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 143 Assert.assertEquals(product, actualRequest.getProduct()); 144 Assert.assertEquals(productId, actualRequest.getProductId()); 145 Assert.assertTrue( 146 channelProvider.isHeaderSent( 147 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 148 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 149 } 150 151 @Test createProductExceptionTest()152 public void createProductExceptionTest() throws Exception { 153 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 154 mockProductService.addException(exception); 155 156 try { 157 BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]"); 158 Product product = Product.newBuilder().build(); 159 String productId = "productId-1051830678"; 160 client.createProduct(parent, product, productId); 161 Assert.fail("No exception raised"); 162 } catch (InvalidArgumentException e) { 163 // Expected exception. 164 } 165 } 166 167 @Test createProductTest2()168 public void createProductTest2() throws Exception { 169 Product expectedResponse = 170 Product.newBuilder() 171 .setName( 172 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]") 173 .toString()) 174 .setId("id3355") 175 .setPrimaryProductId("primaryProductId-857339256") 176 .addAllCollectionMemberIds(new ArrayList<String>()) 177 .setGtin("gtin3183314") 178 .addAllCategories(new ArrayList<String>()) 179 .setTitle("title110371416") 180 .addAllBrands(new ArrayList<String>()) 181 .setDescription("description-1724546052") 182 .setLanguageCode("languageCode-2092349083") 183 .putAllAttributes(new HashMap<String, CustomAttribute>()) 184 .addAllTags(new ArrayList<String>()) 185 .setPriceInfo(PriceInfo.newBuilder().build()) 186 .setRating(Rating.newBuilder().build()) 187 .setAvailableTime(Timestamp.newBuilder().build()) 188 .setAvailableQuantity(Int32Value.newBuilder().build()) 189 .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>()) 190 .setUri("uri116076") 191 .addAllImages(new ArrayList<Image>()) 192 .setAudience(Audience.newBuilder().build()) 193 .setColorInfo(ColorInfo.newBuilder().build()) 194 .addAllSizes(new ArrayList<String>()) 195 .addAllMaterials(new ArrayList<String>()) 196 .addAllPatterns(new ArrayList<String>()) 197 .addAllConditions(new ArrayList<String>()) 198 .addAllPromotions(new ArrayList<Promotion>()) 199 .setPublishTime(Timestamp.newBuilder().build()) 200 .setRetrievableFields(FieldMask.newBuilder().build()) 201 .addAllVariants(new ArrayList<Product>()) 202 .addAllLocalInventories(new ArrayList<LocalInventory>()) 203 .build(); 204 mockProductService.addResponse(expectedResponse); 205 206 String parent = "parent-995424086"; 207 Product product = Product.newBuilder().build(); 208 String productId = "productId-1051830678"; 209 210 Product actualResponse = client.createProduct(parent, product, productId); 211 Assert.assertEquals(expectedResponse, actualResponse); 212 213 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 214 Assert.assertEquals(1, actualRequests.size()); 215 CreateProductRequest actualRequest = ((CreateProductRequest) actualRequests.get(0)); 216 217 Assert.assertEquals(parent, actualRequest.getParent()); 218 Assert.assertEquals(product, actualRequest.getProduct()); 219 Assert.assertEquals(productId, actualRequest.getProductId()); 220 Assert.assertTrue( 221 channelProvider.isHeaderSent( 222 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 223 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 224 } 225 226 @Test createProductExceptionTest2()227 public void createProductExceptionTest2() throws Exception { 228 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 229 mockProductService.addException(exception); 230 231 try { 232 String parent = "parent-995424086"; 233 Product product = Product.newBuilder().build(); 234 String productId = "productId-1051830678"; 235 client.createProduct(parent, product, productId); 236 Assert.fail("No exception raised"); 237 } catch (InvalidArgumentException e) { 238 // Expected exception. 239 } 240 } 241 242 @Test getProductTest()243 public void getProductTest() throws Exception { 244 Product expectedResponse = 245 Product.newBuilder() 246 .setName( 247 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]") 248 .toString()) 249 .setId("id3355") 250 .setPrimaryProductId("primaryProductId-857339256") 251 .addAllCollectionMemberIds(new ArrayList<String>()) 252 .setGtin("gtin3183314") 253 .addAllCategories(new ArrayList<String>()) 254 .setTitle("title110371416") 255 .addAllBrands(new ArrayList<String>()) 256 .setDescription("description-1724546052") 257 .setLanguageCode("languageCode-2092349083") 258 .putAllAttributes(new HashMap<String, CustomAttribute>()) 259 .addAllTags(new ArrayList<String>()) 260 .setPriceInfo(PriceInfo.newBuilder().build()) 261 .setRating(Rating.newBuilder().build()) 262 .setAvailableTime(Timestamp.newBuilder().build()) 263 .setAvailableQuantity(Int32Value.newBuilder().build()) 264 .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>()) 265 .setUri("uri116076") 266 .addAllImages(new ArrayList<Image>()) 267 .setAudience(Audience.newBuilder().build()) 268 .setColorInfo(ColorInfo.newBuilder().build()) 269 .addAllSizes(new ArrayList<String>()) 270 .addAllMaterials(new ArrayList<String>()) 271 .addAllPatterns(new ArrayList<String>()) 272 .addAllConditions(new ArrayList<String>()) 273 .addAllPromotions(new ArrayList<Promotion>()) 274 .setPublishTime(Timestamp.newBuilder().build()) 275 .setRetrievableFields(FieldMask.newBuilder().build()) 276 .addAllVariants(new ArrayList<Product>()) 277 .addAllLocalInventories(new ArrayList<LocalInventory>()) 278 .build(); 279 mockProductService.addResponse(expectedResponse); 280 281 ProductName name = 282 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 283 284 Product actualResponse = client.getProduct(name); 285 Assert.assertEquals(expectedResponse, actualResponse); 286 287 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 288 Assert.assertEquals(1, actualRequests.size()); 289 GetProductRequest actualRequest = ((GetProductRequest) actualRequests.get(0)); 290 291 Assert.assertEquals(name.toString(), actualRequest.getName()); 292 Assert.assertTrue( 293 channelProvider.isHeaderSent( 294 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 295 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 296 } 297 298 @Test getProductExceptionTest()299 public void getProductExceptionTest() throws Exception { 300 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 301 mockProductService.addException(exception); 302 303 try { 304 ProductName name = 305 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 306 client.getProduct(name); 307 Assert.fail("No exception raised"); 308 } catch (InvalidArgumentException e) { 309 // Expected exception. 310 } 311 } 312 313 @Test getProductTest2()314 public void getProductTest2() throws Exception { 315 Product expectedResponse = 316 Product.newBuilder() 317 .setName( 318 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]") 319 .toString()) 320 .setId("id3355") 321 .setPrimaryProductId("primaryProductId-857339256") 322 .addAllCollectionMemberIds(new ArrayList<String>()) 323 .setGtin("gtin3183314") 324 .addAllCategories(new ArrayList<String>()) 325 .setTitle("title110371416") 326 .addAllBrands(new ArrayList<String>()) 327 .setDescription("description-1724546052") 328 .setLanguageCode("languageCode-2092349083") 329 .putAllAttributes(new HashMap<String, CustomAttribute>()) 330 .addAllTags(new ArrayList<String>()) 331 .setPriceInfo(PriceInfo.newBuilder().build()) 332 .setRating(Rating.newBuilder().build()) 333 .setAvailableTime(Timestamp.newBuilder().build()) 334 .setAvailableQuantity(Int32Value.newBuilder().build()) 335 .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>()) 336 .setUri("uri116076") 337 .addAllImages(new ArrayList<Image>()) 338 .setAudience(Audience.newBuilder().build()) 339 .setColorInfo(ColorInfo.newBuilder().build()) 340 .addAllSizes(new ArrayList<String>()) 341 .addAllMaterials(new ArrayList<String>()) 342 .addAllPatterns(new ArrayList<String>()) 343 .addAllConditions(new ArrayList<String>()) 344 .addAllPromotions(new ArrayList<Promotion>()) 345 .setPublishTime(Timestamp.newBuilder().build()) 346 .setRetrievableFields(FieldMask.newBuilder().build()) 347 .addAllVariants(new ArrayList<Product>()) 348 .addAllLocalInventories(new ArrayList<LocalInventory>()) 349 .build(); 350 mockProductService.addResponse(expectedResponse); 351 352 String name = "name3373707"; 353 354 Product actualResponse = client.getProduct(name); 355 Assert.assertEquals(expectedResponse, actualResponse); 356 357 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 358 Assert.assertEquals(1, actualRequests.size()); 359 GetProductRequest actualRequest = ((GetProductRequest) actualRequests.get(0)); 360 361 Assert.assertEquals(name, actualRequest.getName()); 362 Assert.assertTrue( 363 channelProvider.isHeaderSent( 364 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 365 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 366 } 367 368 @Test getProductExceptionTest2()369 public void getProductExceptionTest2() throws Exception { 370 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 371 mockProductService.addException(exception); 372 373 try { 374 String name = "name3373707"; 375 client.getProduct(name); 376 Assert.fail("No exception raised"); 377 } catch (InvalidArgumentException e) { 378 // Expected exception. 379 } 380 } 381 382 @Test listProductsTest()383 public void listProductsTest() throws Exception { 384 Product responsesElement = Product.newBuilder().build(); 385 ListProductsResponse expectedResponse = 386 ListProductsResponse.newBuilder() 387 .setNextPageToken("") 388 .addAllProducts(Arrays.asList(responsesElement)) 389 .build(); 390 mockProductService.addResponse(expectedResponse); 391 392 BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]"); 393 394 ListProductsPagedResponse pagedListResponse = client.listProducts(parent); 395 396 List<Product> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 397 398 Assert.assertEquals(1, resources.size()); 399 Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0)); 400 401 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 402 Assert.assertEquals(1, actualRequests.size()); 403 ListProductsRequest actualRequest = ((ListProductsRequest) actualRequests.get(0)); 404 405 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 406 Assert.assertTrue( 407 channelProvider.isHeaderSent( 408 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 409 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 410 } 411 412 @Test listProductsExceptionTest()413 public void listProductsExceptionTest() throws Exception { 414 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 415 mockProductService.addException(exception); 416 417 try { 418 BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]"); 419 client.listProducts(parent); 420 Assert.fail("No exception raised"); 421 } catch (InvalidArgumentException e) { 422 // Expected exception. 423 } 424 } 425 426 @Test listProductsTest2()427 public void listProductsTest2() throws Exception { 428 Product responsesElement = Product.newBuilder().build(); 429 ListProductsResponse expectedResponse = 430 ListProductsResponse.newBuilder() 431 .setNextPageToken("") 432 .addAllProducts(Arrays.asList(responsesElement)) 433 .build(); 434 mockProductService.addResponse(expectedResponse); 435 436 String parent = "parent-995424086"; 437 438 ListProductsPagedResponse pagedListResponse = client.listProducts(parent); 439 440 List<Product> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 441 442 Assert.assertEquals(1, resources.size()); 443 Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0)); 444 445 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 446 Assert.assertEquals(1, actualRequests.size()); 447 ListProductsRequest actualRequest = ((ListProductsRequest) actualRequests.get(0)); 448 449 Assert.assertEquals(parent, actualRequest.getParent()); 450 Assert.assertTrue( 451 channelProvider.isHeaderSent( 452 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 453 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 454 } 455 456 @Test listProductsExceptionTest2()457 public void listProductsExceptionTest2() throws Exception { 458 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 459 mockProductService.addException(exception); 460 461 try { 462 String parent = "parent-995424086"; 463 client.listProducts(parent); 464 Assert.fail("No exception raised"); 465 } catch (InvalidArgumentException e) { 466 // Expected exception. 467 } 468 } 469 470 @Test updateProductTest()471 public void updateProductTest() throws Exception { 472 Product expectedResponse = 473 Product.newBuilder() 474 .setName( 475 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]") 476 .toString()) 477 .setId("id3355") 478 .setPrimaryProductId("primaryProductId-857339256") 479 .addAllCollectionMemberIds(new ArrayList<String>()) 480 .setGtin("gtin3183314") 481 .addAllCategories(new ArrayList<String>()) 482 .setTitle("title110371416") 483 .addAllBrands(new ArrayList<String>()) 484 .setDescription("description-1724546052") 485 .setLanguageCode("languageCode-2092349083") 486 .putAllAttributes(new HashMap<String, CustomAttribute>()) 487 .addAllTags(new ArrayList<String>()) 488 .setPriceInfo(PriceInfo.newBuilder().build()) 489 .setRating(Rating.newBuilder().build()) 490 .setAvailableTime(Timestamp.newBuilder().build()) 491 .setAvailableQuantity(Int32Value.newBuilder().build()) 492 .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>()) 493 .setUri("uri116076") 494 .addAllImages(new ArrayList<Image>()) 495 .setAudience(Audience.newBuilder().build()) 496 .setColorInfo(ColorInfo.newBuilder().build()) 497 .addAllSizes(new ArrayList<String>()) 498 .addAllMaterials(new ArrayList<String>()) 499 .addAllPatterns(new ArrayList<String>()) 500 .addAllConditions(new ArrayList<String>()) 501 .addAllPromotions(new ArrayList<Promotion>()) 502 .setPublishTime(Timestamp.newBuilder().build()) 503 .setRetrievableFields(FieldMask.newBuilder().build()) 504 .addAllVariants(new ArrayList<Product>()) 505 .addAllLocalInventories(new ArrayList<LocalInventory>()) 506 .build(); 507 mockProductService.addResponse(expectedResponse); 508 509 Product product = Product.newBuilder().build(); 510 FieldMask updateMask = FieldMask.newBuilder().build(); 511 512 Product actualResponse = client.updateProduct(product, updateMask); 513 Assert.assertEquals(expectedResponse, actualResponse); 514 515 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 516 Assert.assertEquals(1, actualRequests.size()); 517 UpdateProductRequest actualRequest = ((UpdateProductRequest) actualRequests.get(0)); 518 519 Assert.assertEquals(product, actualRequest.getProduct()); 520 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 521 Assert.assertTrue( 522 channelProvider.isHeaderSent( 523 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 524 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 525 } 526 527 @Test updateProductExceptionTest()528 public void updateProductExceptionTest() throws Exception { 529 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 530 mockProductService.addException(exception); 531 532 try { 533 Product product = Product.newBuilder().build(); 534 FieldMask updateMask = FieldMask.newBuilder().build(); 535 client.updateProduct(product, updateMask); 536 Assert.fail("No exception raised"); 537 } catch (InvalidArgumentException e) { 538 // Expected exception. 539 } 540 } 541 542 @Test deleteProductTest()543 public void deleteProductTest() throws Exception { 544 Empty expectedResponse = Empty.newBuilder().build(); 545 mockProductService.addResponse(expectedResponse); 546 547 ProductName name = 548 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 549 550 client.deleteProduct(name); 551 552 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 553 Assert.assertEquals(1, actualRequests.size()); 554 DeleteProductRequest actualRequest = ((DeleteProductRequest) actualRequests.get(0)); 555 556 Assert.assertEquals(name.toString(), actualRequest.getName()); 557 Assert.assertTrue( 558 channelProvider.isHeaderSent( 559 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 560 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 561 } 562 563 @Test deleteProductExceptionTest()564 public void deleteProductExceptionTest() throws Exception { 565 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 566 mockProductService.addException(exception); 567 568 try { 569 ProductName name = 570 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 571 client.deleteProduct(name); 572 Assert.fail("No exception raised"); 573 } catch (InvalidArgumentException e) { 574 // Expected exception. 575 } 576 } 577 578 @Test deleteProductTest2()579 public void deleteProductTest2() throws Exception { 580 Empty expectedResponse = Empty.newBuilder().build(); 581 mockProductService.addResponse(expectedResponse); 582 583 String name = "name3373707"; 584 585 client.deleteProduct(name); 586 587 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 588 Assert.assertEquals(1, actualRequests.size()); 589 DeleteProductRequest actualRequest = ((DeleteProductRequest) actualRequests.get(0)); 590 591 Assert.assertEquals(name, actualRequest.getName()); 592 Assert.assertTrue( 593 channelProvider.isHeaderSent( 594 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 595 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 596 } 597 598 @Test deleteProductExceptionTest2()599 public void deleteProductExceptionTest2() throws Exception { 600 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 601 mockProductService.addException(exception); 602 603 try { 604 String name = "name3373707"; 605 client.deleteProduct(name); 606 Assert.fail("No exception raised"); 607 } catch (InvalidArgumentException e) { 608 // Expected exception. 609 } 610 } 611 612 @Test importProductsTest()613 public void importProductsTest() throws Exception { 614 ImportProductsResponse expectedResponse = 615 ImportProductsResponse.newBuilder() 616 .addAllErrorSamples(new ArrayList<Status>()) 617 .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) 618 .build(); 619 Operation resultOperation = 620 Operation.newBuilder() 621 .setName("importProductsTest") 622 .setDone(true) 623 .setResponse(Any.pack(expectedResponse)) 624 .build(); 625 mockProductService.addResponse(resultOperation); 626 627 ImportProductsRequest request = 628 ImportProductsRequest.newBuilder() 629 .setParent(BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString()) 630 .setRequestId("requestId693933066") 631 .setInputConfig(ProductInputConfig.newBuilder().build()) 632 .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) 633 .setUpdateMask(FieldMask.newBuilder().build()) 634 .setNotificationPubsubTopic("notificationPubsubTopic-1361224991") 635 .build(); 636 637 ImportProductsResponse actualResponse = client.importProductsAsync(request).get(); 638 Assert.assertEquals(expectedResponse, actualResponse); 639 640 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 641 Assert.assertEquals(1, actualRequests.size()); 642 ImportProductsRequest actualRequest = ((ImportProductsRequest) actualRequests.get(0)); 643 644 Assert.assertEquals(request.getParent(), actualRequest.getParent()); 645 Assert.assertEquals(request.getRequestId(), actualRequest.getRequestId()); 646 Assert.assertEquals(request.getInputConfig(), actualRequest.getInputConfig()); 647 Assert.assertEquals(request.getErrorsConfig(), actualRequest.getErrorsConfig()); 648 Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); 649 Assert.assertEquals(request.getReconciliationMode(), actualRequest.getReconciliationMode()); 650 Assert.assertEquals( 651 request.getNotificationPubsubTopic(), actualRequest.getNotificationPubsubTopic()); 652 Assert.assertTrue( 653 channelProvider.isHeaderSent( 654 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 655 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 656 } 657 658 @Test importProductsExceptionTest()659 public void importProductsExceptionTest() throws Exception { 660 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 661 mockProductService.addException(exception); 662 663 try { 664 ImportProductsRequest request = 665 ImportProductsRequest.newBuilder() 666 .setParent( 667 BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString()) 668 .setRequestId("requestId693933066") 669 .setInputConfig(ProductInputConfig.newBuilder().build()) 670 .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) 671 .setUpdateMask(FieldMask.newBuilder().build()) 672 .setNotificationPubsubTopic("notificationPubsubTopic-1361224991") 673 .build(); 674 client.importProductsAsync(request).get(); 675 Assert.fail("No exception raised"); 676 } catch (ExecutionException e) { 677 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 678 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 679 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 680 } 681 } 682 683 @Test setInventoryTest()684 public void setInventoryTest() throws Exception { 685 SetInventoryResponse expectedResponse = SetInventoryResponse.newBuilder().build(); 686 Operation resultOperation = 687 Operation.newBuilder() 688 .setName("setInventoryTest") 689 .setDone(true) 690 .setResponse(Any.pack(expectedResponse)) 691 .build(); 692 mockProductService.addResponse(resultOperation); 693 694 Product inventory = Product.newBuilder().build(); 695 FieldMask setMask = FieldMask.newBuilder().build(); 696 697 SetInventoryResponse actualResponse = client.setInventoryAsync(inventory, setMask).get(); 698 Assert.assertEquals(expectedResponse, actualResponse); 699 700 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 701 Assert.assertEquals(1, actualRequests.size()); 702 SetInventoryRequest actualRequest = ((SetInventoryRequest) actualRequests.get(0)); 703 704 Assert.assertEquals(inventory, actualRequest.getInventory()); 705 Assert.assertEquals(setMask, actualRequest.getSetMask()); 706 Assert.assertTrue( 707 channelProvider.isHeaderSent( 708 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 709 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 710 } 711 712 @Test setInventoryExceptionTest()713 public void setInventoryExceptionTest() throws Exception { 714 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 715 mockProductService.addException(exception); 716 717 try { 718 Product inventory = Product.newBuilder().build(); 719 FieldMask setMask = FieldMask.newBuilder().build(); 720 client.setInventoryAsync(inventory, setMask).get(); 721 Assert.fail("No exception raised"); 722 } catch (ExecutionException e) { 723 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 724 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 725 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 726 } 727 } 728 729 @Test addFulfillmentPlacesTest()730 public void addFulfillmentPlacesTest() throws Exception { 731 AddFulfillmentPlacesResponse expectedResponse = 732 AddFulfillmentPlacesResponse.newBuilder().build(); 733 Operation resultOperation = 734 Operation.newBuilder() 735 .setName("addFulfillmentPlacesTest") 736 .setDone(true) 737 .setResponse(Any.pack(expectedResponse)) 738 .build(); 739 mockProductService.addResponse(resultOperation); 740 741 ProductName product = 742 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 743 744 AddFulfillmentPlacesResponse actualResponse = client.addFulfillmentPlacesAsync(product).get(); 745 Assert.assertEquals(expectedResponse, actualResponse); 746 747 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 748 Assert.assertEquals(1, actualRequests.size()); 749 AddFulfillmentPlacesRequest actualRequest = 750 ((AddFulfillmentPlacesRequest) actualRequests.get(0)); 751 752 Assert.assertEquals(product.toString(), actualRequest.getProduct()); 753 Assert.assertTrue( 754 channelProvider.isHeaderSent( 755 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 756 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 757 } 758 759 @Test addFulfillmentPlacesExceptionTest()760 public void addFulfillmentPlacesExceptionTest() throws Exception { 761 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 762 mockProductService.addException(exception); 763 764 try { 765 ProductName product = 766 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 767 client.addFulfillmentPlacesAsync(product).get(); 768 Assert.fail("No exception raised"); 769 } catch (ExecutionException e) { 770 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 771 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 772 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 773 } 774 } 775 776 @Test addFulfillmentPlacesTest2()777 public void addFulfillmentPlacesTest2() throws Exception { 778 AddFulfillmentPlacesResponse expectedResponse = 779 AddFulfillmentPlacesResponse.newBuilder().build(); 780 Operation resultOperation = 781 Operation.newBuilder() 782 .setName("addFulfillmentPlacesTest") 783 .setDone(true) 784 .setResponse(Any.pack(expectedResponse)) 785 .build(); 786 mockProductService.addResponse(resultOperation); 787 788 String product = "product-309474065"; 789 790 AddFulfillmentPlacesResponse actualResponse = client.addFulfillmentPlacesAsync(product).get(); 791 Assert.assertEquals(expectedResponse, actualResponse); 792 793 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 794 Assert.assertEquals(1, actualRequests.size()); 795 AddFulfillmentPlacesRequest actualRequest = 796 ((AddFulfillmentPlacesRequest) actualRequests.get(0)); 797 798 Assert.assertEquals(product, actualRequest.getProduct()); 799 Assert.assertTrue( 800 channelProvider.isHeaderSent( 801 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 802 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 803 } 804 805 @Test addFulfillmentPlacesExceptionTest2()806 public void addFulfillmentPlacesExceptionTest2() throws Exception { 807 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 808 mockProductService.addException(exception); 809 810 try { 811 String product = "product-309474065"; 812 client.addFulfillmentPlacesAsync(product).get(); 813 Assert.fail("No exception raised"); 814 } catch (ExecutionException e) { 815 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 816 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 817 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 818 } 819 } 820 821 @Test removeFulfillmentPlacesTest()822 public void removeFulfillmentPlacesTest() throws Exception { 823 RemoveFulfillmentPlacesResponse expectedResponse = 824 RemoveFulfillmentPlacesResponse.newBuilder().build(); 825 Operation resultOperation = 826 Operation.newBuilder() 827 .setName("removeFulfillmentPlacesTest") 828 .setDone(true) 829 .setResponse(Any.pack(expectedResponse)) 830 .build(); 831 mockProductService.addResponse(resultOperation); 832 833 ProductName product = 834 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 835 836 RemoveFulfillmentPlacesResponse actualResponse = 837 client.removeFulfillmentPlacesAsync(product).get(); 838 Assert.assertEquals(expectedResponse, actualResponse); 839 840 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 841 Assert.assertEquals(1, actualRequests.size()); 842 RemoveFulfillmentPlacesRequest actualRequest = 843 ((RemoveFulfillmentPlacesRequest) actualRequests.get(0)); 844 845 Assert.assertEquals(product.toString(), actualRequest.getProduct()); 846 Assert.assertTrue( 847 channelProvider.isHeaderSent( 848 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 849 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 850 } 851 852 @Test removeFulfillmentPlacesExceptionTest()853 public void removeFulfillmentPlacesExceptionTest() throws Exception { 854 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 855 mockProductService.addException(exception); 856 857 try { 858 ProductName product = 859 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 860 client.removeFulfillmentPlacesAsync(product).get(); 861 Assert.fail("No exception raised"); 862 } catch (ExecutionException e) { 863 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 864 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 865 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 866 } 867 } 868 869 @Test removeFulfillmentPlacesTest2()870 public void removeFulfillmentPlacesTest2() throws Exception { 871 RemoveFulfillmentPlacesResponse expectedResponse = 872 RemoveFulfillmentPlacesResponse.newBuilder().build(); 873 Operation resultOperation = 874 Operation.newBuilder() 875 .setName("removeFulfillmentPlacesTest") 876 .setDone(true) 877 .setResponse(Any.pack(expectedResponse)) 878 .build(); 879 mockProductService.addResponse(resultOperation); 880 881 String product = "product-309474065"; 882 883 RemoveFulfillmentPlacesResponse actualResponse = 884 client.removeFulfillmentPlacesAsync(product).get(); 885 Assert.assertEquals(expectedResponse, actualResponse); 886 887 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 888 Assert.assertEquals(1, actualRequests.size()); 889 RemoveFulfillmentPlacesRequest actualRequest = 890 ((RemoveFulfillmentPlacesRequest) actualRequests.get(0)); 891 892 Assert.assertEquals(product, actualRequest.getProduct()); 893 Assert.assertTrue( 894 channelProvider.isHeaderSent( 895 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 896 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 897 } 898 899 @Test removeFulfillmentPlacesExceptionTest2()900 public void removeFulfillmentPlacesExceptionTest2() throws Exception { 901 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 902 mockProductService.addException(exception); 903 904 try { 905 String product = "product-309474065"; 906 client.removeFulfillmentPlacesAsync(product).get(); 907 Assert.fail("No exception raised"); 908 } catch (ExecutionException e) { 909 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 910 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 911 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 912 } 913 } 914 915 @Test addLocalInventoriesTest()916 public void addLocalInventoriesTest() throws Exception { 917 AddLocalInventoriesResponse expectedResponse = AddLocalInventoriesResponse.newBuilder().build(); 918 Operation resultOperation = 919 Operation.newBuilder() 920 .setName("addLocalInventoriesTest") 921 .setDone(true) 922 .setResponse(Any.pack(expectedResponse)) 923 .build(); 924 mockProductService.addResponse(resultOperation); 925 926 ProductName product = 927 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 928 929 AddLocalInventoriesResponse actualResponse = client.addLocalInventoriesAsync(product).get(); 930 Assert.assertEquals(expectedResponse, actualResponse); 931 932 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 933 Assert.assertEquals(1, actualRequests.size()); 934 AddLocalInventoriesRequest actualRequest = ((AddLocalInventoriesRequest) actualRequests.get(0)); 935 936 Assert.assertEquals(product.toString(), actualRequest.getProduct()); 937 Assert.assertTrue( 938 channelProvider.isHeaderSent( 939 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 940 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 941 } 942 943 @Test addLocalInventoriesExceptionTest()944 public void addLocalInventoriesExceptionTest() throws Exception { 945 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 946 mockProductService.addException(exception); 947 948 try { 949 ProductName product = 950 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 951 client.addLocalInventoriesAsync(product).get(); 952 Assert.fail("No exception raised"); 953 } catch (ExecutionException e) { 954 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 955 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 956 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 957 } 958 } 959 960 @Test addLocalInventoriesTest2()961 public void addLocalInventoriesTest2() throws Exception { 962 AddLocalInventoriesResponse expectedResponse = AddLocalInventoriesResponse.newBuilder().build(); 963 Operation resultOperation = 964 Operation.newBuilder() 965 .setName("addLocalInventoriesTest") 966 .setDone(true) 967 .setResponse(Any.pack(expectedResponse)) 968 .build(); 969 mockProductService.addResponse(resultOperation); 970 971 String product = "product-309474065"; 972 973 AddLocalInventoriesResponse actualResponse = client.addLocalInventoriesAsync(product).get(); 974 Assert.assertEquals(expectedResponse, actualResponse); 975 976 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 977 Assert.assertEquals(1, actualRequests.size()); 978 AddLocalInventoriesRequest actualRequest = ((AddLocalInventoriesRequest) actualRequests.get(0)); 979 980 Assert.assertEquals(product, actualRequest.getProduct()); 981 Assert.assertTrue( 982 channelProvider.isHeaderSent( 983 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 984 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 985 } 986 987 @Test addLocalInventoriesExceptionTest2()988 public void addLocalInventoriesExceptionTest2() throws Exception { 989 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 990 mockProductService.addException(exception); 991 992 try { 993 String product = "product-309474065"; 994 client.addLocalInventoriesAsync(product).get(); 995 Assert.fail("No exception raised"); 996 } catch (ExecutionException e) { 997 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 998 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 999 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1000 } 1001 } 1002 1003 @Test removeLocalInventoriesTest()1004 public void removeLocalInventoriesTest() throws Exception { 1005 RemoveLocalInventoriesResponse expectedResponse = 1006 RemoveLocalInventoriesResponse.newBuilder().build(); 1007 Operation resultOperation = 1008 Operation.newBuilder() 1009 .setName("removeLocalInventoriesTest") 1010 .setDone(true) 1011 .setResponse(Any.pack(expectedResponse)) 1012 .build(); 1013 mockProductService.addResponse(resultOperation); 1014 1015 ProductName product = 1016 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 1017 1018 RemoveLocalInventoriesResponse actualResponse = 1019 client.removeLocalInventoriesAsync(product).get(); 1020 Assert.assertEquals(expectedResponse, actualResponse); 1021 1022 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 1023 Assert.assertEquals(1, actualRequests.size()); 1024 RemoveLocalInventoriesRequest actualRequest = 1025 ((RemoveLocalInventoriesRequest) actualRequests.get(0)); 1026 1027 Assert.assertEquals(product.toString(), actualRequest.getProduct()); 1028 Assert.assertTrue( 1029 channelProvider.isHeaderSent( 1030 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1031 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1032 } 1033 1034 @Test removeLocalInventoriesExceptionTest()1035 public void removeLocalInventoriesExceptionTest() throws Exception { 1036 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1037 mockProductService.addException(exception); 1038 1039 try { 1040 ProductName product = 1041 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]"); 1042 client.removeLocalInventoriesAsync(product).get(); 1043 Assert.fail("No exception raised"); 1044 } catch (ExecutionException e) { 1045 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1046 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1047 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1048 } 1049 } 1050 1051 @Test removeLocalInventoriesTest2()1052 public void removeLocalInventoriesTest2() throws Exception { 1053 RemoveLocalInventoriesResponse expectedResponse = 1054 RemoveLocalInventoriesResponse.newBuilder().build(); 1055 Operation resultOperation = 1056 Operation.newBuilder() 1057 .setName("removeLocalInventoriesTest") 1058 .setDone(true) 1059 .setResponse(Any.pack(expectedResponse)) 1060 .build(); 1061 mockProductService.addResponse(resultOperation); 1062 1063 String product = "product-309474065"; 1064 1065 RemoveLocalInventoriesResponse actualResponse = 1066 client.removeLocalInventoriesAsync(product).get(); 1067 Assert.assertEquals(expectedResponse, actualResponse); 1068 1069 List<AbstractMessage> actualRequests = mockProductService.getRequests(); 1070 Assert.assertEquals(1, actualRequests.size()); 1071 RemoveLocalInventoriesRequest actualRequest = 1072 ((RemoveLocalInventoriesRequest) actualRequests.get(0)); 1073 1074 Assert.assertEquals(product, actualRequest.getProduct()); 1075 Assert.assertTrue( 1076 channelProvider.isHeaderSent( 1077 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1078 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1079 } 1080 1081 @Test removeLocalInventoriesExceptionTest2()1082 public void removeLocalInventoriesExceptionTest2() throws Exception { 1083 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1084 mockProductService.addException(exception); 1085 1086 try { 1087 String product = "product-309474065"; 1088 client.removeLocalInventoriesAsync(product).get(); 1089 Assert.fail("No exception raised"); 1090 } catch (ExecutionException e) { 1091 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1092 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1093 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1094 } 1095 } 1096 } 1097