• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.v2;
18 
19 import static com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse;
20 
21 import com.google.api.gax.core.NoCredentialsProvider;
22 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
23 import com.google.api.gax.httpjson.testing.MockHttpService;
24 import com.google.api.gax.rpc.ApiClientHeaderProvider;
25 import com.google.api.gax.rpc.ApiException;
26 import com.google.api.gax.rpc.ApiExceptionFactory;
27 import com.google.api.gax.rpc.InvalidArgumentException;
28 import com.google.api.gax.rpc.StatusCode;
29 import com.google.api.gax.rpc.testing.FakeStatusCode;
30 import com.google.cloud.retail.v2.stub.HttpJsonProductServiceStub;
31 import com.google.common.collect.Lists;
32 import com.google.longrunning.Operation;
33 import com.google.protobuf.Any;
34 import com.google.protobuf.Empty;
35 import com.google.protobuf.FieldMask;
36 import com.google.protobuf.Int32Value;
37 import com.google.protobuf.Timestamp;
38 import com.google.rpc.Status;
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.concurrent.ExecutionException;
45 import javax.annotation.Generated;
46 import org.junit.After;
47 import org.junit.AfterClass;
48 import org.junit.Assert;
49 import org.junit.Before;
50 import org.junit.BeforeClass;
51 import org.junit.Test;
52 
53 @Generated("by gapic-generator-java")
54 public class ProductServiceClientHttpJsonTest {
55   private static MockHttpService mockService;
56   private static ProductServiceClient client;
57 
58   @BeforeClass
startStaticServer()59   public static void startStaticServer() throws IOException {
60     mockService =
61         new MockHttpService(
62             HttpJsonProductServiceStub.getMethodDescriptors(),
63             ProductServiceSettings.getDefaultEndpoint());
64     ProductServiceSettings settings =
65         ProductServiceSettings.newHttpJsonBuilder()
66             .setTransportChannelProvider(
67                 ProductServiceSettings.defaultHttpJsonTransportProviderBuilder()
68                     .setHttpTransport(mockService)
69                     .build())
70             .setCredentialsProvider(NoCredentialsProvider.create())
71             .build();
72     client = ProductServiceClient.create(settings);
73   }
74 
75   @AfterClass
stopServer()76   public static void stopServer() {
77     client.close();
78   }
79 
80   @Before
setUp()81   public void setUp() {}
82 
83   @After
tearDown()84   public void tearDown() throws Exception {
85     mockService.reset();
86   }
87 
88   @Test
createProductTest()89   public void createProductTest() throws Exception {
90     Product expectedResponse =
91         Product.newBuilder()
92             .setName(
93                 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
94                     .toString())
95             .setId("id3355")
96             .setPrimaryProductId("primaryProductId-857339256")
97             .addAllCollectionMemberIds(new ArrayList<String>())
98             .setGtin("gtin3183314")
99             .addAllCategories(new ArrayList<String>())
100             .setTitle("title110371416")
101             .addAllBrands(new ArrayList<String>())
102             .setDescription("description-1724546052")
103             .setLanguageCode("languageCode-2092349083")
104             .putAllAttributes(new HashMap<String, CustomAttribute>())
105             .addAllTags(new ArrayList<String>())
106             .setPriceInfo(PriceInfo.newBuilder().build())
107             .setRating(Rating.newBuilder().build())
108             .setAvailableTime(Timestamp.newBuilder().build())
109             .setAvailableQuantity(Int32Value.newBuilder().build())
110             .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
111             .setUri("uri116076")
112             .addAllImages(new ArrayList<Image>())
113             .setAudience(Audience.newBuilder().build())
114             .setColorInfo(ColorInfo.newBuilder().build())
115             .addAllSizes(new ArrayList<String>())
116             .addAllMaterials(new ArrayList<String>())
117             .addAllPatterns(new ArrayList<String>())
118             .addAllConditions(new ArrayList<String>())
119             .addAllPromotions(new ArrayList<Promotion>())
120             .setPublishTime(Timestamp.newBuilder().build())
121             .setRetrievableFields(FieldMask.newBuilder().build())
122             .addAllVariants(new ArrayList<Product>())
123             .addAllLocalInventories(new ArrayList<LocalInventory>())
124             .build();
125     mockService.addResponse(expectedResponse);
126 
127     BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]");
128     Product product = Product.newBuilder().build();
129     String productId = "productId-1051830678";
130 
131     Product actualResponse = client.createProduct(parent, product, productId);
132     Assert.assertEquals(expectedResponse, actualResponse);
133 
134     List<String> actualRequests = mockService.getRequestPaths();
135     Assert.assertEquals(1, actualRequests.size());
136 
137     String apiClientHeaderKey =
138         mockService
139             .getRequestHeaders()
140             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
141             .iterator()
142             .next();
143     Assert.assertTrue(
144         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
145             .matcher(apiClientHeaderKey)
146             .matches());
147   }
148 
149   @Test
createProductExceptionTest()150   public void createProductExceptionTest() throws Exception {
151     ApiException exception =
152         ApiExceptionFactory.createException(
153             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
154     mockService.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     mockService.addResponse(expectedResponse);
205 
206     String parent =
207         "projects/project-7087/locations/location-7087/catalogs/catalog-7087/branches/branche-7087";
208     Product product = Product.newBuilder().build();
209     String productId = "productId-1051830678";
210 
211     Product actualResponse = client.createProduct(parent, product, productId);
212     Assert.assertEquals(expectedResponse, actualResponse);
213 
214     List<String> actualRequests = mockService.getRequestPaths();
215     Assert.assertEquals(1, actualRequests.size());
216 
217     String apiClientHeaderKey =
218         mockService
219             .getRequestHeaders()
220             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
221             .iterator()
222             .next();
223     Assert.assertTrue(
224         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
225             .matcher(apiClientHeaderKey)
226             .matches());
227   }
228 
229   @Test
createProductExceptionTest2()230   public void createProductExceptionTest2() throws Exception {
231     ApiException exception =
232         ApiExceptionFactory.createException(
233             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
234     mockService.addException(exception);
235 
236     try {
237       String parent =
238           "projects/project-7087/locations/location-7087/catalogs/catalog-7087/branches/branche-7087";
239       Product product = Product.newBuilder().build();
240       String productId = "productId-1051830678";
241       client.createProduct(parent, product, productId);
242       Assert.fail("No exception raised");
243     } catch (InvalidArgumentException e) {
244       // Expected exception.
245     }
246   }
247 
248   @Test
getProductTest()249   public void getProductTest() throws Exception {
250     Product expectedResponse =
251         Product.newBuilder()
252             .setName(
253                 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
254                     .toString())
255             .setId("id3355")
256             .setPrimaryProductId("primaryProductId-857339256")
257             .addAllCollectionMemberIds(new ArrayList<String>())
258             .setGtin("gtin3183314")
259             .addAllCategories(new ArrayList<String>())
260             .setTitle("title110371416")
261             .addAllBrands(new ArrayList<String>())
262             .setDescription("description-1724546052")
263             .setLanguageCode("languageCode-2092349083")
264             .putAllAttributes(new HashMap<String, CustomAttribute>())
265             .addAllTags(new ArrayList<String>())
266             .setPriceInfo(PriceInfo.newBuilder().build())
267             .setRating(Rating.newBuilder().build())
268             .setAvailableTime(Timestamp.newBuilder().build())
269             .setAvailableQuantity(Int32Value.newBuilder().build())
270             .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
271             .setUri("uri116076")
272             .addAllImages(new ArrayList<Image>())
273             .setAudience(Audience.newBuilder().build())
274             .setColorInfo(ColorInfo.newBuilder().build())
275             .addAllSizes(new ArrayList<String>())
276             .addAllMaterials(new ArrayList<String>())
277             .addAllPatterns(new ArrayList<String>())
278             .addAllConditions(new ArrayList<String>())
279             .addAllPromotions(new ArrayList<Promotion>())
280             .setPublishTime(Timestamp.newBuilder().build())
281             .setRetrievableFields(FieldMask.newBuilder().build())
282             .addAllVariants(new ArrayList<Product>())
283             .addAllLocalInventories(new ArrayList<LocalInventory>())
284             .build();
285     mockService.addResponse(expectedResponse);
286 
287     ProductName name =
288         ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
289 
290     Product actualResponse = client.getProduct(name);
291     Assert.assertEquals(expectedResponse, actualResponse);
292 
293     List<String> actualRequests = mockService.getRequestPaths();
294     Assert.assertEquals(1, actualRequests.size());
295 
296     String apiClientHeaderKey =
297         mockService
298             .getRequestHeaders()
299             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
300             .iterator()
301             .next();
302     Assert.assertTrue(
303         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
304             .matcher(apiClientHeaderKey)
305             .matches());
306   }
307 
308   @Test
getProductExceptionTest()309   public void getProductExceptionTest() throws Exception {
310     ApiException exception =
311         ApiExceptionFactory.createException(
312             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
313     mockService.addException(exception);
314 
315     try {
316       ProductName name =
317           ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
318       client.getProduct(name);
319       Assert.fail("No exception raised");
320     } catch (InvalidArgumentException e) {
321       // Expected exception.
322     }
323   }
324 
325   @Test
getProductTest2()326   public void getProductTest2() throws Exception {
327     Product expectedResponse =
328         Product.newBuilder()
329             .setName(
330                 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
331                     .toString())
332             .setId("id3355")
333             .setPrimaryProductId("primaryProductId-857339256")
334             .addAllCollectionMemberIds(new ArrayList<String>())
335             .setGtin("gtin3183314")
336             .addAllCategories(new ArrayList<String>())
337             .setTitle("title110371416")
338             .addAllBrands(new ArrayList<String>())
339             .setDescription("description-1724546052")
340             .setLanguageCode("languageCode-2092349083")
341             .putAllAttributes(new HashMap<String, CustomAttribute>())
342             .addAllTags(new ArrayList<String>())
343             .setPriceInfo(PriceInfo.newBuilder().build())
344             .setRating(Rating.newBuilder().build())
345             .setAvailableTime(Timestamp.newBuilder().build())
346             .setAvailableQuantity(Int32Value.newBuilder().build())
347             .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
348             .setUri("uri116076")
349             .addAllImages(new ArrayList<Image>())
350             .setAudience(Audience.newBuilder().build())
351             .setColorInfo(ColorInfo.newBuilder().build())
352             .addAllSizes(new ArrayList<String>())
353             .addAllMaterials(new ArrayList<String>())
354             .addAllPatterns(new ArrayList<String>())
355             .addAllConditions(new ArrayList<String>())
356             .addAllPromotions(new ArrayList<Promotion>())
357             .setPublishTime(Timestamp.newBuilder().build())
358             .setRetrievableFields(FieldMask.newBuilder().build())
359             .addAllVariants(new ArrayList<Product>())
360             .addAllLocalInventories(new ArrayList<LocalInventory>())
361             .build();
362     mockService.addResponse(expectedResponse);
363 
364     String name =
365         "projects/project-436/locations/location-436/catalogs/catalog-436/branches/branche-436/products/product-436";
366 
367     Product actualResponse = client.getProduct(name);
368     Assert.assertEquals(expectedResponse, actualResponse);
369 
370     List<String> actualRequests = mockService.getRequestPaths();
371     Assert.assertEquals(1, actualRequests.size());
372 
373     String apiClientHeaderKey =
374         mockService
375             .getRequestHeaders()
376             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
377             .iterator()
378             .next();
379     Assert.assertTrue(
380         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
381             .matcher(apiClientHeaderKey)
382             .matches());
383   }
384 
385   @Test
getProductExceptionTest2()386   public void getProductExceptionTest2() throws Exception {
387     ApiException exception =
388         ApiExceptionFactory.createException(
389             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
390     mockService.addException(exception);
391 
392     try {
393       String name =
394           "projects/project-436/locations/location-436/catalogs/catalog-436/branches/branche-436/products/product-436";
395       client.getProduct(name);
396       Assert.fail("No exception raised");
397     } catch (InvalidArgumentException e) {
398       // Expected exception.
399     }
400   }
401 
402   @Test
listProductsTest()403   public void listProductsTest() throws Exception {
404     Product responsesElement = Product.newBuilder().build();
405     ListProductsResponse expectedResponse =
406         ListProductsResponse.newBuilder()
407             .setNextPageToken("")
408             .addAllProducts(Arrays.asList(responsesElement))
409             .build();
410     mockService.addResponse(expectedResponse);
411 
412     BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]");
413 
414     ListProductsPagedResponse pagedListResponse = client.listProducts(parent);
415 
416     List<Product> resources = Lists.newArrayList(pagedListResponse.iterateAll());
417 
418     Assert.assertEquals(1, resources.size());
419     Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0));
420 
421     List<String> actualRequests = mockService.getRequestPaths();
422     Assert.assertEquals(1, actualRequests.size());
423 
424     String apiClientHeaderKey =
425         mockService
426             .getRequestHeaders()
427             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
428             .iterator()
429             .next();
430     Assert.assertTrue(
431         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
432             .matcher(apiClientHeaderKey)
433             .matches());
434   }
435 
436   @Test
listProductsExceptionTest()437   public void listProductsExceptionTest() throws Exception {
438     ApiException exception =
439         ApiExceptionFactory.createException(
440             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
441     mockService.addException(exception);
442 
443     try {
444       BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]");
445       client.listProducts(parent);
446       Assert.fail("No exception raised");
447     } catch (InvalidArgumentException e) {
448       // Expected exception.
449     }
450   }
451 
452   @Test
listProductsTest2()453   public void listProductsTest2() throws Exception {
454     Product responsesElement = Product.newBuilder().build();
455     ListProductsResponse expectedResponse =
456         ListProductsResponse.newBuilder()
457             .setNextPageToken("")
458             .addAllProducts(Arrays.asList(responsesElement))
459             .build();
460     mockService.addResponse(expectedResponse);
461 
462     String parent =
463         "projects/project-7087/locations/location-7087/catalogs/catalog-7087/branches/branche-7087";
464 
465     ListProductsPagedResponse pagedListResponse = client.listProducts(parent);
466 
467     List<Product> resources = Lists.newArrayList(pagedListResponse.iterateAll());
468 
469     Assert.assertEquals(1, resources.size());
470     Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0));
471 
472     List<String> actualRequests = mockService.getRequestPaths();
473     Assert.assertEquals(1, actualRequests.size());
474 
475     String apiClientHeaderKey =
476         mockService
477             .getRequestHeaders()
478             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
479             .iterator()
480             .next();
481     Assert.assertTrue(
482         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
483             .matcher(apiClientHeaderKey)
484             .matches());
485   }
486 
487   @Test
listProductsExceptionTest2()488   public void listProductsExceptionTest2() throws Exception {
489     ApiException exception =
490         ApiExceptionFactory.createException(
491             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
492     mockService.addException(exception);
493 
494     try {
495       String parent =
496           "projects/project-7087/locations/location-7087/catalogs/catalog-7087/branches/branche-7087";
497       client.listProducts(parent);
498       Assert.fail("No exception raised");
499     } catch (InvalidArgumentException e) {
500       // Expected exception.
501     }
502   }
503 
504   @Test
updateProductTest()505   public void updateProductTest() throws Exception {
506     Product expectedResponse =
507         Product.newBuilder()
508             .setName(
509                 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
510                     .toString())
511             .setId("id3355")
512             .setPrimaryProductId("primaryProductId-857339256")
513             .addAllCollectionMemberIds(new ArrayList<String>())
514             .setGtin("gtin3183314")
515             .addAllCategories(new ArrayList<String>())
516             .setTitle("title110371416")
517             .addAllBrands(new ArrayList<String>())
518             .setDescription("description-1724546052")
519             .setLanguageCode("languageCode-2092349083")
520             .putAllAttributes(new HashMap<String, CustomAttribute>())
521             .addAllTags(new ArrayList<String>())
522             .setPriceInfo(PriceInfo.newBuilder().build())
523             .setRating(Rating.newBuilder().build())
524             .setAvailableTime(Timestamp.newBuilder().build())
525             .setAvailableQuantity(Int32Value.newBuilder().build())
526             .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
527             .setUri("uri116076")
528             .addAllImages(new ArrayList<Image>())
529             .setAudience(Audience.newBuilder().build())
530             .setColorInfo(ColorInfo.newBuilder().build())
531             .addAllSizes(new ArrayList<String>())
532             .addAllMaterials(new ArrayList<String>())
533             .addAllPatterns(new ArrayList<String>())
534             .addAllConditions(new ArrayList<String>())
535             .addAllPromotions(new ArrayList<Promotion>())
536             .setPublishTime(Timestamp.newBuilder().build())
537             .setRetrievableFields(FieldMask.newBuilder().build())
538             .addAllVariants(new ArrayList<Product>())
539             .addAllLocalInventories(new ArrayList<LocalInventory>())
540             .build();
541     mockService.addResponse(expectedResponse);
542 
543     Product product =
544         Product.newBuilder()
545             .setName(
546                 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
547                     .toString())
548             .setId("id3355")
549             .setPrimaryProductId("primaryProductId-857339256")
550             .addAllCollectionMemberIds(new ArrayList<String>())
551             .setGtin("gtin3183314")
552             .addAllCategories(new ArrayList<String>())
553             .setTitle("title110371416")
554             .addAllBrands(new ArrayList<String>())
555             .setDescription("description-1724546052")
556             .setLanguageCode("languageCode-2092349083")
557             .putAllAttributes(new HashMap<String, CustomAttribute>())
558             .addAllTags(new ArrayList<String>())
559             .setPriceInfo(PriceInfo.newBuilder().build())
560             .setRating(Rating.newBuilder().build())
561             .setAvailableTime(Timestamp.newBuilder().build())
562             .setAvailableQuantity(Int32Value.newBuilder().build())
563             .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
564             .setUri("uri116076")
565             .addAllImages(new ArrayList<Image>())
566             .setAudience(Audience.newBuilder().build())
567             .setColorInfo(ColorInfo.newBuilder().build())
568             .addAllSizes(new ArrayList<String>())
569             .addAllMaterials(new ArrayList<String>())
570             .addAllPatterns(new ArrayList<String>())
571             .addAllConditions(new ArrayList<String>())
572             .addAllPromotions(new ArrayList<Promotion>())
573             .setPublishTime(Timestamp.newBuilder().build())
574             .setRetrievableFields(FieldMask.newBuilder().build())
575             .addAllVariants(new ArrayList<Product>())
576             .addAllLocalInventories(new ArrayList<LocalInventory>())
577             .build();
578     FieldMask updateMask = FieldMask.newBuilder().build();
579 
580     Product actualResponse = client.updateProduct(product, updateMask);
581     Assert.assertEquals(expectedResponse, actualResponse);
582 
583     List<String> actualRequests = mockService.getRequestPaths();
584     Assert.assertEquals(1, actualRequests.size());
585 
586     String apiClientHeaderKey =
587         mockService
588             .getRequestHeaders()
589             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
590             .iterator()
591             .next();
592     Assert.assertTrue(
593         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
594             .matcher(apiClientHeaderKey)
595             .matches());
596   }
597 
598   @Test
updateProductExceptionTest()599   public void updateProductExceptionTest() throws Exception {
600     ApiException exception =
601         ApiExceptionFactory.createException(
602             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
603     mockService.addException(exception);
604 
605     try {
606       Product product =
607           Product.newBuilder()
608               .setName(
609                   ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
610                       .toString())
611               .setId("id3355")
612               .setPrimaryProductId("primaryProductId-857339256")
613               .addAllCollectionMemberIds(new ArrayList<String>())
614               .setGtin("gtin3183314")
615               .addAllCategories(new ArrayList<String>())
616               .setTitle("title110371416")
617               .addAllBrands(new ArrayList<String>())
618               .setDescription("description-1724546052")
619               .setLanguageCode("languageCode-2092349083")
620               .putAllAttributes(new HashMap<String, CustomAttribute>())
621               .addAllTags(new ArrayList<String>())
622               .setPriceInfo(PriceInfo.newBuilder().build())
623               .setRating(Rating.newBuilder().build())
624               .setAvailableTime(Timestamp.newBuilder().build())
625               .setAvailableQuantity(Int32Value.newBuilder().build())
626               .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
627               .setUri("uri116076")
628               .addAllImages(new ArrayList<Image>())
629               .setAudience(Audience.newBuilder().build())
630               .setColorInfo(ColorInfo.newBuilder().build())
631               .addAllSizes(new ArrayList<String>())
632               .addAllMaterials(new ArrayList<String>())
633               .addAllPatterns(new ArrayList<String>())
634               .addAllConditions(new ArrayList<String>())
635               .addAllPromotions(new ArrayList<Promotion>())
636               .setPublishTime(Timestamp.newBuilder().build())
637               .setRetrievableFields(FieldMask.newBuilder().build())
638               .addAllVariants(new ArrayList<Product>())
639               .addAllLocalInventories(new ArrayList<LocalInventory>())
640               .build();
641       FieldMask updateMask = FieldMask.newBuilder().build();
642       client.updateProduct(product, updateMask);
643       Assert.fail("No exception raised");
644     } catch (InvalidArgumentException e) {
645       // Expected exception.
646     }
647   }
648 
649   @Test
deleteProductTest()650   public void deleteProductTest() throws Exception {
651     Empty expectedResponse = Empty.newBuilder().build();
652     mockService.addResponse(expectedResponse);
653 
654     ProductName name =
655         ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
656 
657     client.deleteProduct(name);
658 
659     List<String> actualRequests = mockService.getRequestPaths();
660     Assert.assertEquals(1, actualRequests.size());
661 
662     String apiClientHeaderKey =
663         mockService
664             .getRequestHeaders()
665             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
666             .iterator()
667             .next();
668     Assert.assertTrue(
669         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
670             .matcher(apiClientHeaderKey)
671             .matches());
672   }
673 
674   @Test
deleteProductExceptionTest()675   public void deleteProductExceptionTest() throws Exception {
676     ApiException exception =
677         ApiExceptionFactory.createException(
678             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
679     mockService.addException(exception);
680 
681     try {
682       ProductName name =
683           ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
684       client.deleteProduct(name);
685       Assert.fail("No exception raised");
686     } catch (InvalidArgumentException e) {
687       // Expected exception.
688     }
689   }
690 
691   @Test
deleteProductTest2()692   public void deleteProductTest2() throws Exception {
693     Empty expectedResponse = Empty.newBuilder().build();
694     mockService.addResponse(expectedResponse);
695 
696     String name =
697         "projects/project-436/locations/location-436/catalogs/catalog-436/branches/branche-436/products/product-436";
698 
699     client.deleteProduct(name);
700 
701     List<String> actualRequests = mockService.getRequestPaths();
702     Assert.assertEquals(1, actualRequests.size());
703 
704     String apiClientHeaderKey =
705         mockService
706             .getRequestHeaders()
707             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
708             .iterator()
709             .next();
710     Assert.assertTrue(
711         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
712             .matcher(apiClientHeaderKey)
713             .matches());
714   }
715 
716   @Test
deleteProductExceptionTest2()717   public void deleteProductExceptionTest2() throws Exception {
718     ApiException exception =
719         ApiExceptionFactory.createException(
720             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
721     mockService.addException(exception);
722 
723     try {
724       String name =
725           "projects/project-436/locations/location-436/catalogs/catalog-436/branches/branche-436/products/product-436";
726       client.deleteProduct(name);
727       Assert.fail("No exception raised");
728     } catch (InvalidArgumentException e) {
729       // Expected exception.
730     }
731   }
732 
733   @Test
importProductsTest()734   public void importProductsTest() throws Exception {
735     ImportProductsResponse expectedResponse =
736         ImportProductsResponse.newBuilder()
737             .addAllErrorSamples(new ArrayList<Status>())
738             .setErrorsConfig(ImportErrorsConfig.newBuilder().build())
739             .build();
740     Operation resultOperation =
741         Operation.newBuilder()
742             .setName("importProductsTest")
743             .setDone(true)
744             .setResponse(Any.pack(expectedResponse))
745             .build();
746     mockService.addResponse(resultOperation);
747 
748     ImportProductsRequest request =
749         ImportProductsRequest.newBuilder()
750             .setParent(BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString())
751             .setRequestId("requestId693933066")
752             .setInputConfig(ProductInputConfig.newBuilder().build())
753             .setErrorsConfig(ImportErrorsConfig.newBuilder().build())
754             .setUpdateMask(FieldMask.newBuilder().build())
755             .setNotificationPubsubTopic("notificationPubsubTopic-1361224991")
756             .build();
757 
758     ImportProductsResponse actualResponse = client.importProductsAsync(request).get();
759     Assert.assertEquals(expectedResponse, actualResponse);
760 
761     List<String> actualRequests = mockService.getRequestPaths();
762     Assert.assertEquals(1, actualRequests.size());
763 
764     String apiClientHeaderKey =
765         mockService
766             .getRequestHeaders()
767             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
768             .iterator()
769             .next();
770     Assert.assertTrue(
771         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
772             .matcher(apiClientHeaderKey)
773             .matches());
774   }
775 
776   @Test
importProductsExceptionTest()777   public void importProductsExceptionTest() throws Exception {
778     ApiException exception =
779         ApiExceptionFactory.createException(
780             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
781     mockService.addException(exception);
782 
783     try {
784       ImportProductsRequest request =
785           ImportProductsRequest.newBuilder()
786               .setParent(
787                   BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString())
788               .setRequestId("requestId693933066")
789               .setInputConfig(ProductInputConfig.newBuilder().build())
790               .setErrorsConfig(ImportErrorsConfig.newBuilder().build())
791               .setUpdateMask(FieldMask.newBuilder().build())
792               .setNotificationPubsubTopic("notificationPubsubTopic-1361224991")
793               .build();
794       client.importProductsAsync(request).get();
795       Assert.fail("No exception raised");
796     } catch (ExecutionException e) {
797     }
798   }
799 
800   @Test
setInventoryTest()801   public void setInventoryTest() throws Exception {
802     SetInventoryResponse expectedResponse = SetInventoryResponse.newBuilder().build();
803     Operation resultOperation =
804         Operation.newBuilder()
805             .setName("setInventoryTest")
806             .setDone(true)
807             .setResponse(Any.pack(expectedResponse))
808             .build();
809     mockService.addResponse(resultOperation);
810 
811     Product inventory =
812         Product.newBuilder()
813             .setName(
814                 ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
815                     .toString())
816             .setId("id3355")
817             .setPrimaryProductId("primaryProductId-857339256")
818             .addAllCollectionMemberIds(new ArrayList<String>())
819             .setGtin("gtin3183314")
820             .addAllCategories(new ArrayList<String>())
821             .setTitle("title110371416")
822             .addAllBrands(new ArrayList<String>())
823             .setDescription("description-1724546052")
824             .setLanguageCode("languageCode-2092349083")
825             .putAllAttributes(new HashMap<String, CustomAttribute>())
826             .addAllTags(new ArrayList<String>())
827             .setPriceInfo(PriceInfo.newBuilder().build())
828             .setRating(Rating.newBuilder().build())
829             .setAvailableTime(Timestamp.newBuilder().build())
830             .setAvailableQuantity(Int32Value.newBuilder().build())
831             .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
832             .setUri("uri116076")
833             .addAllImages(new ArrayList<Image>())
834             .setAudience(Audience.newBuilder().build())
835             .setColorInfo(ColorInfo.newBuilder().build())
836             .addAllSizes(new ArrayList<String>())
837             .addAllMaterials(new ArrayList<String>())
838             .addAllPatterns(new ArrayList<String>())
839             .addAllConditions(new ArrayList<String>())
840             .addAllPromotions(new ArrayList<Promotion>())
841             .setPublishTime(Timestamp.newBuilder().build())
842             .setRetrievableFields(FieldMask.newBuilder().build())
843             .addAllVariants(new ArrayList<Product>())
844             .addAllLocalInventories(new ArrayList<LocalInventory>())
845             .build();
846     FieldMask setMask = FieldMask.newBuilder().build();
847 
848     SetInventoryResponse actualResponse = client.setInventoryAsync(inventory, setMask).get();
849     Assert.assertEquals(expectedResponse, actualResponse);
850 
851     List<String> actualRequests = mockService.getRequestPaths();
852     Assert.assertEquals(1, actualRequests.size());
853 
854     String apiClientHeaderKey =
855         mockService
856             .getRequestHeaders()
857             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
858             .iterator()
859             .next();
860     Assert.assertTrue(
861         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
862             .matcher(apiClientHeaderKey)
863             .matches());
864   }
865 
866   @Test
setInventoryExceptionTest()867   public void setInventoryExceptionTest() throws Exception {
868     ApiException exception =
869         ApiExceptionFactory.createException(
870             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
871     mockService.addException(exception);
872 
873     try {
874       Product inventory =
875           Product.newBuilder()
876               .setName(
877                   ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]")
878                       .toString())
879               .setId("id3355")
880               .setPrimaryProductId("primaryProductId-857339256")
881               .addAllCollectionMemberIds(new ArrayList<String>())
882               .setGtin("gtin3183314")
883               .addAllCategories(new ArrayList<String>())
884               .setTitle("title110371416")
885               .addAllBrands(new ArrayList<String>())
886               .setDescription("description-1724546052")
887               .setLanguageCode("languageCode-2092349083")
888               .putAllAttributes(new HashMap<String, CustomAttribute>())
889               .addAllTags(new ArrayList<String>())
890               .setPriceInfo(PriceInfo.newBuilder().build())
891               .setRating(Rating.newBuilder().build())
892               .setAvailableTime(Timestamp.newBuilder().build())
893               .setAvailableQuantity(Int32Value.newBuilder().build())
894               .addAllFulfillmentInfo(new ArrayList<FulfillmentInfo>())
895               .setUri("uri116076")
896               .addAllImages(new ArrayList<Image>())
897               .setAudience(Audience.newBuilder().build())
898               .setColorInfo(ColorInfo.newBuilder().build())
899               .addAllSizes(new ArrayList<String>())
900               .addAllMaterials(new ArrayList<String>())
901               .addAllPatterns(new ArrayList<String>())
902               .addAllConditions(new ArrayList<String>())
903               .addAllPromotions(new ArrayList<Promotion>())
904               .setPublishTime(Timestamp.newBuilder().build())
905               .setRetrievableFields(FieldMask.newBuilder().build())
906               .addAllVariants(new ArrayList<Product>())
907               .addAllLocalInventories(new ArrayList<LocalInventory>())
908               .build();
909       FieldMask setMask = FieldMask.newBuilder().build();
910       client.setInventoryAsync(inventory, setMask).get();
911       Assert.fail("No exception raised");
912     } catch (ExecutionException e) {
913     }
914   }
915 
916   @Test
addFulfillmentPlacesTest()917   public void addFulfillmentPlacesTest() throws Exception {
918     AddFulfillmentPlacesResponse expectedResponse =
919         AddFulfillmentPlacesResponse.newBuilder().build();
920     Operation resultOperation =
921         Operation.newBuilder()
922             .setName("addFulfillmentPlacesTest")
923             .setDone(true)
924             .setResponse(Any.pack(expectedResponse))
925             .build();
926     mockService.addResponse(resultOperation);
927 
928     ProductName product =
929         ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
930 
931     AddFulfillmentPlacesResponse actualResponse = client.addFulfillmentPlacesAsync(product).get();
932     Assert.assertEquals(expectedResponse, actualResponse);
933 
934     List<String> actualRequests = mockService.getRequestPaths();
935     Assert.assertEquals(1, actualRequests.size());
936 
937     String apiClientHeaderKey =
938         mockService
939             .getRequestHeaders()
940             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
941             .iterator()
942             .next();
943     Assert.assertTrue(
944         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
945             .matcher(apiClientHeaderKey)
946             .matches());
947   }
948 
949   @Test
addFulfillmentPlacesExceptionTest()950   public void addFulfillmentPlacesExceptionTest() throws Exception {
951     ApiException exception =
952         ApiExceptionFactory.createException(
953             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
954     mockService.addException(exception);
955 
956     try {
957       ProductName product =
958           ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
959       client.addFulfillmentPlacesAsync(product).get();
960       Assert.fail("No exception raised");
961     } catch (ExecutionException e) {
962     }
963   }
964 
965   @Test
addFulfillmentPlacesTest2()966   public void addFulfillmentPlacesTest2() throws Exception {
967     AddFulfillmentPlacesResponse expectedResponse =
968         AddFulfillmentPlacesResponse.newBuilder().build();
969     Operation resultOperation =
970         Operation.newBuilder()
971             .setName("addFulfillmentPlacesTest")
972             .setDone(true)
973             .setResponse(Any.pack(expectedResponse))
974             .build();
975     mockService.addResponse(resultOperation);
976 
977     String product =
978         "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
979 
980     AddFulfillmentPlacesResponse actualResponse = client.addFulfillmentPlacesAsync(product).get();
981     Assert.assertEquals(expectedResponse, actualResponse);
982 
983     List<String> actualRequests = mockService.getRequestPaths();
984     Assert.assertEquals(1, actualRequests.size());
985 
986     String apiClientHeaderKey =
987         mockService
988             .getRequestHeaders()
989             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
990             .iterator()
991             .next();
992     Assert.assertTrue(
993         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
994             .matcher(apiClientHeaderKey)
995             .matches());
996   }
997 
998   @Test
addFulfillmentPlacesExceptionTest2()999   public void addFulfillmentPlacesExceptionTest2() throws Exception {
1000     ApiException exception =
1001         ApiExceptionFactory.createException(
1002             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1003     mockService.addException(exception);
1004 
1005     try {
1006       String product =
1007           "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1008       client.addFulfillmentPlacesAsync(product).get();
1009       Assert.fail("No exception raised");
1010     } catch (ExecutionException e) {
1011     }
1012   }
1013 
1014   @Test
removeFulfillmentPlacesTest()1015   public void removeFulfillmentPlacesTest() throws Exception {
1016     RemoveFulfillmentPlacesResponse expectedResponse =
1017         RemoveFulfillmentPlacesResponse.newBuilder().build();
1018     Operation resultOperation =
1019         Operation.newBuilder()
1020             .setName("removeFulfillmentPlacesTest")
1021             .setDone(true)
1022             .setResponse(Any.pack(expectedResponse))
1023             .build();
1024     mockService.addResponse(resultOperation);
1025 
1026     ProductName product =
1027         ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
1028 
1029     RemoveFulfillmentPlacesResponse actualResponse =
1030         client.removeFulfillmentPlacesAsync(product).get();
1031     Assert.assertEquals(expectedResponse, actualResponse);
1032 
1033     List<String> actualRequests = mockService.getRequestPaths();
1034     Assert.assertEquals(1, actualRequests.size());
1035 
1036     String apiClientHeaderKey =
1037         mockService
1038             .getRequestHeaders()
1039             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1040             .iterator()
1041             .next();
1042     Assert.assertTrue(
1043         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1044             .matcher(apiClientHeaderKey)
1045             .matches());
1046   }
1047 
1048   @Test
removeFulfillmentPlacesExceptionTest()1049   public void removeFulfillmentPlacesExceptionTest() throws Exception {
1050     ApiException exception =
1051         ApiExceptionFactory.createException(
1052             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1053     mockService.addException(exception);
1054 
1055     try {
1056       ProductName product =
1057           ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
1058       client.removeFulfillmentPlacesAsync(product).get();
1059       Assert.fail("No exception raised");
1060     } catch (ExecutionException e) {
1061     }
1062   }
1063 
1064   @Test
removeFulfillmentPlacesTest2()1065   public void removeFulfillmentPlacesTest2() throws Exception {
1066     RemoveFulfillmentPlacesResponse expectedResponse =
1067         RemoveFulfillmentPlacesResponse.newBuilder().build();
1068     Operation resultOperation =
1069         Operation.newBuilder()
1070             .setName("removeFulfillmentPlacesTest")
1071             .setDone(true)
1072             .setResponse(Any.pack(expectedResponse))
1073             .build();
1074     mockService.addResponse(resultOperation);
1075 
1076     String product =
1077         "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1078 
1079     RemoveFulfillmentPlacesResponse actualResponse =
1080         client.removeFulfillmentPlacesAsync(product).get();
1081     Assert.assertEquals(expectedResponse, actualResponse);
1082 
1083     List<String> actualRequests = mockService.getRequestPaths();
1084     Assert.assertEquals(1, actualRequests.size());
1085 
1086     String apiClientHeaderKey =
1087         mockService
1088             .getRequestHeaders()
1089             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1090             .iterator()
1091             .next();
1092     Assert.assertTrue(
1093         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1094             .matcher(apiClientHeaderKey)
1095             .matches());
1096   }
1097 
1098   @Test
removeFulfillmentPlacesExceptionTest2()1099   public void removeFulfillmentPlacesExceptionTest2() throws Exception {
1100     ApiException exception =
1101         ApiExceptionFactory.createException(
1102             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1103     mockService.addException(exception);
1104 
1105     try {
1106       String product =
1107           "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1108       client.removeFulfillmentPlacesAsync(product).get();
1109       Assert.fail("No exception raised");
1110     } catch (ExecutionException e) {
1111     }
1112   }
1113 
1114   @Test
addLocalInventoriesTest()1115   public void addLocalInventoriesTest() throws Exception {
1116     AddLocalInventoriesResponse expectedResponse = AddLocalInventoriesResponse.newBuilder().build();
1117     Operation resultOperation =
1118         Operation.newBuilder()
1119             .setName("addLocalInventoriesTest")
1120             .setDone(true)
1121             .setResponse(Any.pack(expectedResponse))
1122             .build();
1123     mockService.addResponse(resultOperation);
1124 
1125     ProductName product =
1126         ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
1127 
1128     AddLocalInventoriesResponse actualResponse = client.addLocalInventoriesAsync(product).get();
1129     Assert.assertEquals(expectedResponse, actualResponse);
1130 
1131     List<String> actualRequests = mockService.getRequestPaths();
1132     Assert.assertEquals(1, actualRequests.size());
1133 
1134     String apiClientHeaderKey =
1135         mockService
1136             .getRequestHeaders()
1137             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1138             .iterator()
1139             .next();
1140     Assert.assertTrue(
1141         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1142             .matcher(apiClientHeaderKey)
1143             .matches());
1144   }
1145 
1146   @Test
addLocalInventoriesExceptionTest()1147   public void addLocalInventoriesExceptionTest() throws Exception {
1148     ApiException exception =
1149         ApiExceptionFactory.createException(
1150             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1151     mockService.addException(exception);
1152 
1153     try {
1154       ProductName product =
1155           ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
1156       client.addLocalInventoriesAsync(product).get();
1157       Assert.fail("No exception raised");
1158     } catch (ExecutionException e) {
1159     }
1160   }
1161 
1162   @Test
addLocalInventoriesTest2()1163   public void addLocalInventoriesTest2() throws Exception {
1164     AddLocalInventoriesResponse expectedResponse = AddLocalInventoriesResponse.newBuilder().build();
1165     Operation resultOperation =
1166         Operation.newBuilder()
1167             .setName("addLocalInventoriesTest")
1168             .setDone(true)
1169             .setResponse(Any.pack(expectedResponse))
1170             .build();
1171     mockService.addResponse(resultOperation);
1172 
1173     String product =
1174         "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1175 
1176     AddLocalInventoriesResponse actualResponse = client.addLocalInventoriesAsync(product).get();
1177     Assert.assertEquals(expectedResponse, actualResponse);
1178 
1179     List<String> actualRequests = mockService.getRequestPaths();
1180     Assert.assertEquals(1, actualRequests.size());
1181 
1182     String apiClientHeaderKey =
1183         mockService
1184             .getRequestHeaders()
1185             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1186             .iterator()
1187             .next();
1188     Assert.assertTrue(
1189         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1190             .matcher(apiClientHeaderKey)
1191             .matches());
1192   }
1193 
1194   @Test
addLocalInventoriesExceptionTest2()1195   public void addLocalInventoriesExceptionTest2() throws Exception {
1196     ApiException exception =
1197         ApiExceptionFactory.createException(
1198             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1199     mockService.addException(exception);
1200 
1201     try {
1202       String product =
1203           "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1204       client.addLocalInventoriesAsync(product).get();
1205       Assert.fail("No exception raised");
1206     } catch (ExecutionException e) {
1207     }
1208   }
1209 
1210   @Test
removeLocalInventoriesTest()1211   public void removeLocalInventoriesTest() throws Exception {
1212     RemoveLocalInventoriesResponse expectedResponse =
1213         RemoveLocalInventoriesResponse.newBuilder().build();
1214     Operation resultOperation =
1215         Operation.newBuilder()
1216             .setName("removeLocalInventoriesTest")
1217             .setDone(true)
1218             .setResponse(Any.pack(expectedResponse))
1219             .build();
1220     mockService.addResponse(resultOperation);
1221 
1222     ProductName product =
1223         ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
1224 
1225     RemoveLocalInventoriesResponse actualResponse =
1226         client.removeLocalInventoriesAsync(product).get();
1227     Assert.assertEquals(expectedResponse, actualResponse);
1228 
1229     List<String> actualRequests = mockService.getRequestPaths();
1230     Assert.assertEquals(1, actualRequests.size());
1231 
1232     String apiClientHeaderKey =
1233         mockService
1234             .getRequestHeaders()
1235             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1236             .iterator()
1237             .next();
1238     Assert.assertTrue(
1239         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1240             .matcher(apiClientHeaderKey)
1241             .matches());
1242   }
1243 
1244   @Test
removeLocalInventoriesExceptionTest()1245   public void removeLocalInventoriesExceptionTest() throws Exception {
1246     ApiException exception =
1247         ApiExceptionFactory.createException(
1248             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1249     mockService.addException(exception);
1250 
1251     try {
1252       ProductName product =
1253           ProductName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]", "[PRODUCT]");
1254       client.removeLocalInventoriesAsync(product).get();
1255       Assert.fail("No exception raised");
1256     } catch (ExecutionException e) {
1257     }
1258   }
1259 
1260   @Test
removeLocalInventoriesTest2()1261   public void removeLocalInventoriesTest2() throws Exception {
1262     RemoveLocalInventoriesResponse expectedResponse =
1263         RemoveLocalInventoriesResponse.newBuilder().build();
1264     Operation resultOperation =
1265         Operation.newBuilder()
1266             .setName("removeLocalInventoriesTest")
1267             .setDone(true)
1268             .setResponse(Any.pack(expectedResponse))
1269             .build();
1270     mockService.addResponse(resultOperation);
1271 
1272     String product =
1273         "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1274 
1275     RemoveLocalInventoriesResponse actualResponse =
1276         client.removeLocalInventoriesAsync(product).get();
1277     Assert.assertEquals(expectedResponse, actualResponse);
1278 
1279     List<String> actualRequests = mockService.getRequestPaths();
1280     Assert.assertEquals(1, actualRequests.size());
1281 
1282     String apiClientHeaderKey =
1283         mockService
1284             .getRequestHeaders()
1285             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1286             .iterator()
1287             .next();
1288     Assert.assertTrue(
1289         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1290             .matcher(apiClientHeaderKey)
1291             .matches());
1292   }
1293 
1294   @Test
removeLocalInventoriesExceptionTest2()1295   public void removeLocalInventoriesExceptionTest2() throws Exception {
1296     ApiException exception =
1297         ApiExceptionFactory.createException(
1298             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1299     mockService.addException(exception);
1300 
1301     try {
1302       String product =
1303           "projects/project-3856/locations/location-3856/catalogs/catalog-3856/branches/branche-3856/products/product-3856";
1304       client.removeLocalInventoriesAsync(product).get();
1305       Assert.fail("No exception raised");
1306     } catch (ExecutionException e) {
1307     }
1308   }
1309 }
1310