• 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.recommendationengine.v1beta1;
18 
19 import static com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient.ListCatalogItemsPagedResponse;
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.recommendationengine.v1beta1.stub.HttpJsonCatalogServiceStub;
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.rpc.Status;
37 import java.io.IOException;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.List;
41 import java.util.concurrent.ExecutionException;
42 import javax.annotation.Generated;
43 import org.junit.After;
44 import org.junit.AfterClass;
45 import org.junit.Assert;
46 import org.junit.Before;
47 import org.junit.BeforeClass;
48 import org.junit.Test;
49 
50 @Generated("by gapic-generator-java")
51 public class CatalogServiceClientHttpJsonTest {
52   private static MockHttpService mockService;
53   private static CatalogServiceClient client;
54 
55   @BeforeClass
startStaticServer()56   public static void startStaticServer() throws IOException {
57     mockService =
58         new MockHttpService(
59             HttpJsonCatalogServiceStub.getMethodDescriptors(),
60             CatalogServiceSettings.getDefaultEndpoint());
61     CatalogServiceSettings settings =
62         CatalogServiceSettings.newHttpJsonBuilder()
63             .setTransportChannelProvider(
64                 CatalogServiceSettings.defaultHttpJsonTransportProviderBuilder()
65                     .setHttpTransport(mockService)
66                     .build())
67             .setCredentialsProvider(NoCredentialsProvider.create())
68             .build();
69     client = CatalogServiceClient.create(settings);
70   }
71 
72   @AfterClass
stopServer()73   public static void stopServer() {
74     client.close();
75   }
76 
77   @Before
setUp()78   public void setUp() {}
79 
80   @After
tearDown()81   public void tearDown() throws Exception {
82     mockService.reset();
83   }
84 
85   @Test
createCatalogItemTest()86   public void createCatalogItemTest() throws Exception {
87     CatalogItem expectedResponse =
88         CatalogItem.newBuilder()
89             .setId("id3355")
90             .addAllCategoryHierarchies(new ArrayList<CatalogItem.CategoryHierarchy>())
91             .setTitle("title110371416")
92             .setDescription("description-1724546052")
93             .setItemAttributes(FeatureMap.newBuilder().build())
94             .setLanguageCode("languageCode-2092349083")
95             .addAllTags(new ArrayList<String>())
96             .setItemGroupId("itemGroupId-240489113")
97             .build();
98     mockService.addResponse(expectedResponse);
99 
100     CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
101     CatalogItem catalogItem = CatalogItem.newBuilder().build();
102 
103     CatalogItem actualResponse = client.createCatalogItem(parent, catalogItem);
104     Assert.assertEquals(expectedResponse, actualResponse);
105 
106     List<String> actualRequests = mockService.getRequestPaths();
107     Assert.assertEquals(1, actualRequests.size());
108 
109     String apiClientHeaderKey =
110         mockService
111             .getRequestHeaders()
112             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
113             .iterator()
114             .next();
115     Assert.assertTrue(
116         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
117             .matcher(apiClientHeaderKey)
118             .matches());
119   }
120 
121   @Test
createCatalogItemExceptionTest()122   public void createCatalogItemExceptionTest() throws Exception {
123     ApiException exception =
124         ApiExceptionFactory.createException(
125             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
126     mockService.addException(exception);
127 
128     try {
129       CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
130       CatalogItem catalogItem = CatalogItem.newBuilder().build();
131       client.createCatalogItem(parent, catalogItem);
132       Assert.fail("No exception raised");
133     } catch (InvalidArgumentException e) {
134       // Expected exception.
135     }
136   }
137 
138   @Test
createCatalogItemTest2()139   public void createCatalogItemTest2() throws Exception {
140     CatalogItem expectedResponse =
141         CatalogItem.newBuilder()
142             .setId("id3355")
143             .addAllCategoryHierarchies(new ArrayList<CatalogItem.CategoryHierarchy>())
144             .setTitle("title110371416")
145             .setDescription("description-1724546052")
146             .setItemAttributes(FeatureMap.newBuilder().build())
147             .setLanguageCode("languageCode-2092349083")
148             .addAllTags(new ArrayList<String>())
149             .setItemGroupId("itemGroupId-240489113")
150             .build();
151     mockService.addResponse(expectedResponse);
152 
153     String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
154     CatalogItem catalogItem = CatalogItem.newBuilder().build();
155 
156     CatalogItem actualResponse = client.createCatalogItem(parent, catalogItem);
157     Assert.assertEquals(expectedResponse, actualResponse);
158 
159     List<String> actualRequests = mockService.getRequestPaths();
160     Assert.assertEquals(1, actualRequests.size());
161 
162     String apiClientHeaderKey =
163         mockService
164             .getRequestHeaders()
165             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
166             .iterator()
167             .next();
168     Assert.assertTrue(
169         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
170             .matcher(apiClientHeaderKey)
171             .matches());
172   }
173 
174   @Test
createCatalogItemExceptionTest2()175   public void createCatalogItemExceptionTest2() throws Exception {
176     ApiException exception =
177         ApiExceptionFactory.createException(
178             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
179     mockService.addException(exception);
180 
181     try {
182       String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
183       CatalogItem catalogItem = CatalogItem.newBuilder().build();
184       client.createCatalogItem(parent, catalogItem);
185       Assert.fail("No exception raised");
186     } catch (InvalidArgumentException e) {
187       // Expected exception.
188     }
189   }
190 
191   @Test
getCatalogItemTest()192   public void getCatalogItemTest() throws Exception {
193     CatalogItem expectedResponse =
194         CatalogItem.newBuilder()
195             .setId("id3355")
196             .addAllCategoryHierarchies(new ArrayList<CatalogItem.CategoryHierarchy>())
197             .setTitle("title110371416")
198             .setDescription("description-1724546052")
199             .setItemAttributes(FeatureMap.newBuilder().build())
200             .setLanguageCode("languageCode-2092349083")
201             .addAllTags(new ArrayList<String>())
202             .setItemGroupId("itemGroupId-240489113")
203             .build();
204     mockService.addResponse(expectedResponse);
205 
206     CatalogItemPathName name =
207         CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]");
208 
209     CatalogItem actualResponse = client.getCatalogItem(name);
210     Assert.assertEquals(expectedResponse, actualResponse);
211 
212     List<String> actualRequests = mockService.getRequestPaths();
213     Assert.assertEquals(1, actualRequests.size());
214 
215     String apiClientHeaderKey =
216         mockService
217             .getRequestHeaders()
218             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
219             .iterator()
220             .next();
221     Assert.assertTrue(
222         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
223             .matcher(apiClientHeaderKey)
224             .matches());
225   }
226 
227   @Test
getCatalogItemExceptionTest()228   public void getCatalogItemExceptionTest() throws Exception {
229     ApiException exception =
230         ApiExceptionFactory.createException(
231             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
232     mockService.addException(exception);
233 
234     try {
235       CatalogItemPathName name =
236           CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]");
237       client.getCatalogItem(name);
238       Assert.fail("No exception raised");
239     } catch (InvalidArgumentException e) {
240       // Expected exception.
241     }
242   }
243 
244   @Test
getCatalogItemTest2()245   public void getCatalogItemTest2() throws Exception {
246     CatalogItem expectedResponse =
247         CatalogItem.newBuilder()
248             .setId("id3355")
249             .addAllCategoryHierarchies(new ArrayList<CatalogItem.CategoryHierarchy>())
250             .setTitle("title110371416")
251             .setDescription("description-1724546052")
252             .setItemAttributes(FeatureMap.newBuilder().build())
253             .setLanguageCode("languageCode-2092349083")
254             .addAllTags(new ArrayList<String>())
255             .setItemGroupId("itemGroupId-240489113")
256             .build();
257     mockService.addResponse(expectedResponse);
258 
259     String name =
260         "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923";
261 
262     CatalogItem actualResponse = client.getCatalogItem(name);
263     Assert.assertEquals(expectedResponse, actualResponse);
264 
265     List<String> actualRequests = mockService.getRequestPaths();
266     Assert.assertEquals(1, actualRequests.size());
267 
268     String apiClientHeaderKey =
269         mockService
270             .getRequestHeaders()
271             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
272             .iterator()
273             .next();
274     Assert.assertTrue(
275         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
276             .matcher(apiClientHeaderKey)
277             .matches());
278   }
279 
280   @Test
getCatalogItemExceptionTest2()281   public void getCatalogItemExceptionTest2() throws Exception {
282     ApiException exception =
283         ApiExceptionFactory.createException(
284             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
285     mockService.addException(exception);
286 
287     try {
288       String name =
289           "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923";
290       client.getCatalogItem(name);
291       Assert.fail("No exception raised");
292     } catch (InvalidArgumentException e) {
293       // Expected exception.
294     }
295   }
296 
297   @Test
listCatalogItemsTest()298   public void listCatalogItemsTest() throws Exception {
299     CatalogItem responsesElement = CatalogItem.newBuilder().build();
300     ListCatalogItemsResponse expectedResponse =
301         ListCatalogItemsResponse.newBuilder()
302             .setNextPageToken("")
303             .addAllCatalogItems(Arrays.asList(responsesElement))
304             .build();
305     mockService.addResponse(expectedResponse);
306 
307     CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
308     String filter = "filter-1274492040";
309 
310     ListCatalogItemsPagedResponse pagedListResponse = client.listCatalogItems(parent, filter);
311 
312     List<CatalogItem> resources = Lists.newArrayList(pagedListResponse.iterateAll());
313 
314     Assert.assertEquals(1, resources.size());
315     Assert.assertEquals(expectedResponse.getCatalogItemsList().get(0), resources.get(0));
316 
317     List<String> actualRequests = mockService.getRequestPaths();
318     Assert.assertEquals(1, actualRequests.size());
319 
320     String apiClientHeaderKey =
321         mockService
322             .getRequestHeaders()
323             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
324             .iterator()
325             .next();
326     Assert.assertTrue(
327         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
328             .matcher(apiClientHeaderKey)
329             .matches());
330   }
331 
332   @Test
listCatalogItemsExceptionTest()333   public void listCatalogItemsExceptionTest() throws Exception {
334     ApiException exception =
335         ApiExceptionFactory.createException(
336             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
337     mockService.addException(exception);
338 
339     try {
340       CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
341       String filter = "filter-1274492040";
342       client.listCatalogItems(parent, filter);
343       Assert.fail("No exception raised");
344     } catch (InvalidArgumentException e) {
345       // Expected exception.
346     }
347   }
348 
349   @Test
listCatalogItemsTest2()350   public void listCatalogItemsTest2() throws Exception {
351     CatalogItem responsesElement = CatalogItem.newBuilder().build();
352     ListCatalogItemsResponse expectedResponse =
353         ListCatalogItemsResponse.newBuilder()
354             .setNextPageToken("")
355             .addAllCatalogItems(Arrays.asList(responsesElement))
356             .build();
357     mockService.addResponse(expectedResponse);
358 
359     String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
360     String filter = "filter-1274492040";
361 
362     ListCatalogItemsPagedResponse pagedListResponse = client.listCatalogItems(parent, filter);
363 
364     List<CatalogItem> resources = Lists.newArrayList(pagedListResponse.iterateAll());
365 
366     Assert.assertEquals(1, resources.size());
367     Assert.assertEquals(expectedResponse.getCatalogItemsList().get(0), resources.get(0));
368 
369     List<String> actualRequests = mockService.getRequestPaths();
370     Assert.assertEquals(1, actualRequests.size());
371 
372     String apiClientHeaderKey =
373         mockService
374             .getRequestHeaders()
375             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
376             .iterator()
377             .next();
378     Assert.assertTrue(
379         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
380             .matcher(apiClientHeaderKey)
381             .matches());
382   }
383 
384   @Test
listCatalogItemsExceptionTest2()385   public void listCatalogItemsExceptionTest2() throws Exception {
386     ApiException exception =
387         ApiExceptionFactory.createException(
388             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
389     mockService.addException(exception);
390 
391     try {
392       String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
393       String filter = "filter-1274492040";
394       client.listCatalogItems(parent, filter);
395       Assert.fail("No exception raised");
396     } catch (InvalidArgumentException e) {
397       // Expected exception.
398     }
399   }
400 
401   @Test
updateCatalogItemTest()402   public void updateCatalogItemTest() throws Exception {
403     CatalogItem expectedResponse =
404         CatalogItem.newBuilder()
405             .setId("id3355")
406             .addAllCategoryHierarchies(new ArrayList<CatalogItem.CategoryHierarchy>())
407             .setTitle("title110371416")
408             .setDescription("description-1724546052")
409             .setItemAttributes(FeatureMap.newBuilder().build())
410             .setLanguageCode("languageCode-2092349083")
411             .addAllTags(new ArrayList<String>())
412             .setItemGroupId("itemGroupId-240489113")
413             .build();
414     mockService.addResponse(expectedResponse);
415 
416     CatalogItemPathName name =
417         CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]");
418     CatalogItem catalogItem = CatalogItem.newBuilder().build();
419     FieldMask updateMask = FieldMask.newBuilder().build();
420 
421     CatalogItem actualResponse = client.updateCatalogItem(name, catalogItem, updateMask);
422     Assert.assertEquals(expectedResponse, actualResponse);
423 
424     List<String> actualRequests = mockService.getRequestPaths();
425     Assert.assertEquals(1, actualRequests.size());
426 
427     String apiClientHeaderKey =
428         mockService
429             .getRequestHeaders()
430             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
431             .iterator()
432             .next();
433     Assert.assertTrue(
434         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
435             .matcher(apiClientHeaderKey)
436             .matches());
437   }
438 
439   @Test
updateCatalogItemExceptionTest()440   public void updateCatalogItemExceptionTest() throws Exception {
441     ApiException exception =
442         ApiExceptionFactory.createException(
443             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
444     mockService.addException(exception);
445 
446     try {
447       CatalogItemPathName name =
448           CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]");
449       CatalogItem catalogItem = CatalogItem.newBuilder().build();
450       FieldMask updateMask = FieldMask.newBuilder().build();
451       client.updateCatalogItem(name, catalogItem, updateMask);
452       Assert.fail("No exception raised");
453     } catch (InvalidArgumentException e) {
454       // Expected exception.
455     }
456   }
457 
458   @Test
updateCatalogItemTest2()459   public void updateCatalogItemTest2() throws Exception {
460     CatalogItem expectedResponse =
461         CatalogItem.newBuilder()
462             .setId("id3355")
463             .addAllCategoryHierarchies(new ArrayList<CatalogItem.CategoryHierarchy>())
464             .setTitle("title110371416")
465             .setDescription("description-1724546052")
466             .setItemAttributes(FeatureMap.newBuilder().build())
467             .setLanguageCode("languageCode-2092349083")
468             .addAllTags(new ArrayList<String>())
469             .setItemGroupId("itemGroupId-240489113")
470             .build();
471     mockService.addResponse(expectedResponse);
472 
473     String name =
474         "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923";
475     CatalogItem catalogItem = CatalogItem.newBuilder().build();
476     FieldMask updateMask = FieldMask.newBuilder().build();
477 
478     CatalogItem actualResponse = client.updateCatalogItem(name, catalogItem, updateMask);
479     Assert.assertEquals(expectedResponse, actualResponse);
480 
481     List<String> actualRequests = mockService.getRequestPaths();
482     Assert.assertEquals(1, actualRequests.size());
483 
484     String apiClientHeaderKey =
485         mockService
486             .getRequestHeaders()
487             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
488             .iterator()
489             .next();
490     Assert.assertTrue(
491         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
492             .matcher(apiClientHeaderKey)
493             .matches());
494   }
495 
496   @Test
updateCatalogItemExceptionTest2()497   public void updateCatalogItemExceptionTest2() throws Exception {
498     ApiException exception =
499         ApiExceptionFactory.createException(
500             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
501     mockService.addException(exception);
502 
503     try {
504       String name =
505           "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923";
506       CatalogItem catalogItem = CatalogItem.newBuilder().build();
507       FieldMask updateMask = FieldMask.newBuilder().build();
508       client.updateCatalogItem(name, catalogItem, updateMask);
509       Assert.fail("No exception raised");
510     } catch (InvalidArgumentException e) {
511       // Expected exception.
512     }
513   }
514 
515   @Test
deleteCatalogItemTest()516   public void deleteCatalogItemTest() throws Exception {
517     Empty expectedResponse = Empty.newBuilder().build();
518     mockService.addResponse(expectedResponse);
519 
520     CatalogItemPathName name =
521         CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]");
522 
523     client.deleteCatalogItem(name);
524 
525     List<String> actualRequests = mockService.getRequestPaths();
526     Assert.assertEquals(1, actualRequests.size());
527 
528     String apiClientHeaderKey =
529         mockService
530             .getRequestHeaders()
531             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
532             .iterator()
533             .next();
534     Assert.assertTrue(
535         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
536             .matcher(apiClientHeaderKey)
537             .matches());
538   }
539 
540   @Test
deleteCatalogItemExceptionTest()541   public void deleteCatalogItemExceptionTest() throws Exception {
542     ApiException exception =
543         ApiExceptionFactory.createException(
544             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
545     mockService.addException(exception);
546 
547     try {
548       CatalogItemPathName name =
549           CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]");
550       client.deleteCatalogItem(name);
551       Assert.fail("No exception raised");
552     } catch (InvalidArgumentException e) {
553       // Expected exception.
554     }
555   }
556 
557   @Test
deleteCatalogItemTest2()558   public void deleteCatalogItemTest2() throws Exception {
559     Empty expectedResponse = Empty.newBuilder().build();
560     mockService.addResponse(expectedResponse);
561 
562     String name =
563         "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923";
564 
565     client.deleteCatalogItem(name);
566 
567     List<String> actualRequests = mockService.getRequestPaths();
568     Assert.assertEquals(1, actualRequests.size());
569 
570     String apiClientHeaderKey =
571         mockService
572             .getRequestHeaders()
573             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
574             .iterator()
575             .next();
576     Assert.assertTrue(
577         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
578             .matcher(apiClientHeaderKey)
579             .matches());
580   }
581 
582   @Test
deleteCatalogItemExceptionTest2()583   public void deleteCatalogItemExceptionTest2() throws Exception {
584     ApiException exception =
585         ApiExceptionFactory.createException(
586             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
587     mockService.addException(exception);
588 
589     try {
590       String name =
591           "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923";
592       client.deleteCatalogItem(name);
593       Assert.fail("No exception raised");
594     } catch (InvalidArgumentException e) {
595       // Expected exception.
596     }
597   }
598 
599   @Test
importCatalogItemsTest()600   public void importCatalogItemsTest() throws Exception {
601     ImportCatalogItemsResponse expectedResponse =
602         ImportCatalogItemsResponse.newBuilder()
603             .addAllErrorSamples(new ArrayList<Status>())
604             .setErrorsConfig(ImportErrorsConfig.newBuilder().build())
605             .build();
606     Operation resultOperation =
607         Operation.newBuilder()
608             .setName("importCatalogItemsTest")
609             .setDone(true)
610             .setResponse(Any.pack(expectedResponse))
611             .build();
612     mockService.addResponse(resultOperation);
613 
614     CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
615     String requestId = "requestId693933066";
616     InputConfig inputConfig = InputConfig.newBuilder().build();
617     ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build();
618 
619     ImportCatalogItemsResponse actualResponse =
620         client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).get();
621     Assert.assertEquals(expectedResponse, actualResponse);
622 
623     List<String> actualRequests = mockService.getRequestPaths();
624     Assert.assertEquals(1, actualRequests.size());
625 
626     String apiClientHeaderKey =
627         mockService
628             .getRequestHeaders()
629             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
630             .iterator()
631             .next();
632     Assert.assertTrue(
633         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
634             .matcher(apiClientHeaderKey)
635             .matches());
636   }
637 
638   @Test
importCatalogItemsExceptionTest()639   public void importCatalogItemsExceptionTest() throws Exception {
640     ApiException exception =
641         ApiExceptionFactory.createException(
642             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
643     mockService.addException(exception);
644 
645     try {
646       CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
647       String requestId = "requestId693933066";
648       InputConfig inputConfig = InputConfig.newBuilder().build();
649       ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build();
650       client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).get();
651       Assert.fail("No exception raised");
652     } catch (ExecutionException e) {
653     }
654   }
655 
656   @Test
importCatalogItemsTest2()657   public void importCatalogItemsTest2() throws Exception {
658     ImportCatalogItemsResponse expectedResponse =
659         ImportCatalogItemsResponse.newBuilder()
660             .addAllErrorSamples(new ArrayList<Status>())
661             .setErrorsConfig(ImportErrorsConfig.newBuilder().build())
662             .build();
663     Operation resultOperation =
664         Operation.newBuilder()
665             .setName("importCatalogItemsTest")
666             .setDone(true)
667             .setResponse(Any.pack(expectedResponse))
668             .build();
669     mockService.addResponse(resultOperation);
670 
671     String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
672     String requestId = "requestId693933066";
673     InputConfig inputConfig = InputConfig.newBuilder().build();
674     ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build();
675 
676     ImportCatalogItemsResponse actualResponse =
677         client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).get();
678     Assert.assertEquals(expectedResponse, actualResponse);
679 
680     List<String> actualRequests = mockService.getRequestPaths();
681     Assert.assertEquals(1, actualRequests.size());
682 
683     String apiClientHeaderKey =
684         mockService
685             .getRequestHeaders()
686             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
687             .iterator()
688             .next();
689     Assert.assertTrue(
690         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
691             .matcher(apiClientHeaderKey)
692             .matches());
693   }
694 
695   @Test
importCatalogItemsExceptionTest2()696   public void importCatalogItemsExceptionTest2() throws Exception {
697     ApiException exception =
698         ApiExceptionFactory.createException(
699             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
700     mockService.addException(exception);
701 
702     try {
703       String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
704       String requestId = "requestId693933066";
705       InputConfig inputConfig = InputConfig.newBuilder().build();
706       ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build();
707       client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).get();
708       Assert.fail("No exception raised");
709     } catch (ExecutionException e) {
710     }
711   }
712 }
713