• 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.v2beta;
18 
19 import static com.google.cloud.retail.v2beta.ServingConfigServiceClient.ListServingConfigsPagedResponse;
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.v2beta.stub.HttpJsonServingConfigServiceStub;
31 import com.google.common.collect.Lists;
32 import com.google.protobuf.Empty;
33 import com.google.protobuf.FieldMask;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.List;
38 import javax.annotation.Generated;
39 import org.junit.After;
40 import org.junit.AfterClass;
41 import org.junit.Assert;
42 import org.junit.Before;
43 import org.junit.BeforeClass;
44 import org.junit.Test;
45 
46 @Generated("by gapic-generator-java")
47 public class ServingConfigServiceClientHttpJsonTest {
48   private static MockHttpService mockService;
49   private static ServingConfigServiceClient client;
50 
51   @BeforeClass
startStaticServer()52   public static void startStaticServer() throws IOException {
53     mockService =
54         new MockHttpService(
55             HttpJsonServingConfigServiceStub.getMethodDescriptors(),
56             ServingConfigServiceSettings.getDefaultEndpoint());
57     ServingConfigServiceSettings settings =
58         ServingConfigServiceSettings.newHttpJsonBuilder()
59             .setTransportChannelProvider(
60                 ServingConfigServiceSettings.defaultHttpJsonTransportProviderBuilder()
61                     .setHttpTransport(mockService)
62                     .build())
63             .setCredentialsProvider(NoCredentialsProvider.create())
64             .build();
65     client = ServingConfigServiceClient.create(settings);
66   }
67 
68   @AfterClass
stopServer()69   public static void stopServer() {
70     client.close();
71   }
72 
73   @Before
setUp()74   public void setUp() {}
75 
76   @After
tearDown()77   public void tearDown() throws Exception {
78     mockService.reset();
79   }
80 
81   @Test
createServingConfigTest()82   public void createServingConfigTest() throws Exception {
83     ServingConfig expectedResponse =
84         ServingConfig.newBuilder()
85             .setName(
86                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
87                     .toString())
88             .setDisplayName("displayName1714148973")
89             .setModelId("modelId1226956324")
90             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
91             .addAllFacetControlIds(new ArrayList<String>())
92             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
93             .addAllBoostControlIds(new ArrayList<String>())
94             .addAllFilterControlIds(new ArrayList<String>())
95             .addAllRedirectControlIds(new ArrayList<String>())
96             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
97             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
98             .addAllDoNotAssociateControlIds(new ArrayList<String>())
99             .addAllReplacementControlIds(new ArrayList<String>())
100             .addAllIgnoreControlIds(new ArrayList<String>())
101             .setDiversityLevel("diversityLevel578206123")
102             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
103             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
104             .addAllSolutionTypes(new ArrayList<SolutionType>())
105             .build();
106     mockService.addResponse(expectedResponse);
107 
108     CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
109     ServingConfig servingConfig = ServingConfig.newBuilder().build();
110     String servingConfigId = "servingConfigId-831052759";
111 
112     ServingConfig actualResponse =
113         client.createServingConfig(parent, servingConfig, servingConfigId);
114     Assert.assertEquals(expectedResponse, actualResponse);
115 
116     List<String> actualRequests = mockService.getRequestPaths();
117     Assert.assertEquals(1, actualRequests.size());
118 
119     String apiClientHeaderKey =
120         mockService
121             .getRequestHeaders()
122             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
123             .iterator()
124             .next();
125     Assert.assertTrue(
126         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
127             .matcher(apiClientHeaderKey)
128             .matches());
129   }
130 
131   @Test
createServingConfigExceptionTest()132   public void createServingConfigExceptionTest() throws Exception {
133     ApiException exception =
134         ApiExceptionFactory.createException(
135             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
136     mockService.addException(exception);
137 
138     try {
139       CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
140       ServingConfig servingConfig = ServingConfig.newBuilder().build();
141       String servingConfigId = "servingConfigId-831052759";
142       client.createServingConfig(parent, servingConfig, servingConfigId);
143       Assert.fail("No exception raised");
144     } catch (InvalidArgumentException e) {
145       // Expected exception.
146     }
147   }
148 
149   @Test
createServingConfigTest2()150   public void createServingConfigTest2() throws Exception {
151     ServingConfig expectedResponse =
152         ServingConfig.newBuilder()
153             .setName(
154                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
155                     .toString())
156             .setDisplayName("displayName1714148973")
157             .setModelId("modelId1226956324")
158             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
159             .addAllFacetControlIds(new ArrayList<String>())
160             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
161             .addAllBoostControlIds(new ArrayList<String>())
162             .addAllFilterControlIds(new ArrayList<String>())
163             .addAllRedirectControlIds(new ArrayList<String>())
164             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
165             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
166             .addAllDoNotAssociateControlIds(new ArrayList<String>())
167             .addAllReplacementControlIds(new ArrayList<String>())
168             .addAllIgnoreControlIds(new ArrayList<String>())
169             .setDiversityLevel("diversityLevel578206123")
170             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
171             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
172             .addAllSolutionTypes(new ArrayList<SolutionType>())
173             .build();
174     mockService.addResponse(expectedResponse);
175 
176     String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
177     ServingConfig servingConfig = ServingConfig.newBuilder().build();
178     String servingConfigId = "servingConfigId-831052759";
179 
180     ServingConfig actualResponse =
181         client.createServingConfig(parent, servingConfig, servingConfigId);
182     Assert.assertEquals(expectedResponse, actualResponse);
183 
184     List<String> actualRequests = mockService.getRequestPaths();
185     Assert.assertEquals(1, actualRequests.size());
186 
187     String apiClientHeaderKey =
188         mockService
189             .getRequestHeaders()
190             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
191             .iterator()
192             .next();
193     Assert.assertTrue(
194         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
195             .matcher(apiClientHeaderKey)
196             .matches());
197   }
198 
199   @Test
createServingConfigExceptionTest2()200   public void createServingConfigExceptionTest2() throws Exception {
201     ApiException exception =
202         ApiExceptionFactory.createException(
203             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
204     mockService.addException(exception);
205 
206     try {
207       String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
208       ServingConfig servingConfig = ServingConfig.newBuilder().build();
209       String servingConfigId = "servingConfigId-831052759";
210       client.createServingConfig(parent, servingConfig, servingConfigId);
211       Assert.fail("No exception raised");
212     } catch (InvalidArgumentException e) {
213       // Expected exception.
214     }
215   }
216 
217   @Test
deleteServingConfigTest()218   public void deleteServingConfigTest() throws Exception {
219     Empty expectedResponse = Empty.newBuilder().build();
220     mockService.addResponse(expectedResponse);
221 
222     ServingConfigName name =
223         ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
224 
225     client.deleteServingConfig(name);
226 
227     List<String> actualRequests = mockService.getRequestPaths();
228     Assert.assertEquals(1, actualRequests.size());
229 
230     String apiClientHeaderKey =
231         mockService
232             .getRequestHeaders()
233             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
234             .iterator()
235             .next();
236     Assert.assertTrue(
237         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
238             .matcher(apiClientHeaderKey)
239             .matches());
240   }
241 
242   @Test
deleteServingConfigExceptionTest()243   public void deleteServingConfigExceptionTest() throws Exception {
244     ApiException exception =
245         ApiExceptionFactory.createException(
246             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
247     mockService.addException(exception);
248 
249     try {
250       ServingConfigName name =
251           ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
252       client.deleteServingConfig(name);
253       Assert.fail("No exception raised");
254     } catch (InvalidArgumentException e) {
255       // Expected exception.
256     }
257   }
258 
259   @Test
deleteServingConfigTest2()260   public void deleteServingConfigTest2() throws Exception {
261     Empty expectedResponse = Empty.newBuilder().build();
262     mockService.addResponse(expectedResponse);
263 
264     String name =
265         "projects/project-4507/locations/location-4507/catalogs/catalog-4507/servingConfigs/servingConfig-4507";
266 
267     client.deleteServingConfig(name);
268 
269     List<String> actualRequests = mockService.getRequestPaths();
270     Assert.assertEquals(1, actualRequests.size());
271 
272     String apiClientHeaderKey =
273         mockService
274             .getRequestHeaders()
275             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
276             .iterator()
277             .next();
278     Assert.assertTrue(
279         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
280             .matcher(apiClientHeaderKey)
281             .matches());
282   }
283 
284   @Test
deleteServingConfigExceptionTest2()285   public void deleteServingConfigExceptionTest2() throws Exception {
286     ApiException exception =
287         ApiExceptionFactory.createException(
288             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
289     mockService.addException(exception);
290 
291     try {
292       String name =
293           "projects/project-4507/locations/location-4507/catalogs/catalog-4507/servingConfigs/servingConfig-4507";
294       client.deleteServingConfig(name);
295       Assert.fail("No exception raised");
296     } catch (InvalidArgumentException e) {
297       // Expected exception.
298     }
299   }
300 
301   @Test
updateServingConfigTest()302   public void updateServingConfigTest() throws Exception {
303     ServingConfig expectedResponse =
304         ServingConfig.newBuilder()
305             .setName(
306                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
307                     .toString())
308             .setDisplayName("displayName1714148973")
309             .setModelId("modelId1226956324")
310             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
311             .addAllFacetControlIds(new ArrayList<String>())
312             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
313             .addAllBoostControlIds(new ArrayList<String>())
314             .addAllFilterControlIds(new ArrayList<String>())
315             .addAllRedirectControlIds(new ArrayList<String>())
316             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
317             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
318             .addAllDoNotAssociateControlIds(new ArrayList<String>())
319             .addAllReplacementControlIds(new ArrayList<String>())
320             .addAllIgnoreControlIds(new ArrayList<String>())
321             .setDiversityLevel("diversityLevel578206123")
322             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
323             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
324             .addAllSolutionTypes(new ArrayList<SolutionType>())
325             .build();
326     mockService.addResponse(expectedResponse);
327 
328     ServingConfig servingConfig =
329         ServingConfig.newBuilder()
330             .setName(
331                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
332                     .toString())
333             .setDisplayName("displayName1714148973")
334             .setModelId("modelId1226956324")
335             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
336             .addAllFacetControlIds(new ArrayList<String>())
337             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
338             .addAllBoostControlIds(new ArrayList<String>())
339             .addAllFilterControlIds(new ArrayList<String>())
340             .addAllRedirectControlIds(new ArrayList<String>())
341             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
342             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
343             .addAllDoNotAssociateControlIds(new ArrayList<String>())
344             .addAllReplacementControlIds(new ArrayList<String>())
345             .addAllIgnoreControlIds(new ArrayList<String>())
346             .setDiversityLevel("diversityLevel578206123")
347             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
348             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
349             .addAllSolutionTypes(new ArrayList<SolutionType>())
350             .build();
351     FieldMask updateMask = FieldMask.newBuilder().build();
352 
353     ServingConfig actualResponse = client.updateServingConfig(servingConfig, updateMask);
354     Assert.assertEquals(expectedResponse, actualResponse);
355 
356     List<String> actualRequests = mockService.getRequestPaths();
357     Assert.assertEquals(1, actualRequests.size());
358 
359     String apiClientHeaderKey =
360         mockService
361             .getRequestHeaders()
362             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
363             .iterator()
364             .next();
365     Assert.assertTrue(
366         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
367             .matcher(apiClientHeaderKey)
368             .matches());
369   }
370 
371   @Test
updateServingConfigExceptionTest()372   public void updateServingConfigExceptionTest() throws Exception {
373     ApiException exception =
374         ApiExceptionFactory.createException(
375             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
376     mockService.addException(exception);
377 
378     try {
379       ServingConfig servingConfig =
380           ServingConfig.newBuilder()
381               .setName(
382                   ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
383                       .toString())
384               .setDisplayName("displayName1714148973")
385               .setModelId("modelId1226956324")
386               .setPriceRerankingLevel("priceRerankingLevel-1925548982")
387               .addAllFacetControlIds(new ArrayList<String>())
388               .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
389               .addAllBoostControlIds(new ArrayList<String>())
390               .addAllFilterControlIds(new ArrayList<String>())
391               .addAllRedirectControlIds(new ArrayList<String>())
392               .addAllTwowaySynonymsControlIds(new ArrayList<String>())
393               .addAllOnewaySynonymsControlIds(new ArrayList<String>())
394               .addAllDoNotAssociateControlIds(new ArrayList<String>())
395               .addAllReplacementControlIds(new ArrayList<String>())
396               .addAllIgnoreControlIds(new ArrayList<String>())
397               .setDiversityLevel("diversityLevel578206123")
398               .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
399               .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
400               .addAllSolutionTypes(new ArrayList<SolutionType>())
401               .build();
402       FieldMask updateMask = FieldMask.newBuilder().build();
403       client.updateServingConfig(servingConfig, updateMask);
404       Assert.fail("No exception raised");
405     } catch (InvalidArgumentException e) {
406       // Expected exception.
407     }
408   }
409 
410   @Test
getServingConfigTest()411   public void getServingConfigTest() throws Exception {
412     ServingConfig expectedResponse =
413         ServingConfig.newBuilder()
414             .setName(
415                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
416                     .toString())
417             .setDisplayName("displayName1714148973")
418             .setModelId("modelId1226956324")
419             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
420             .addAllFacetControlIds(new ArrayList<String>())
421             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
422             .addAllBoostControlIds(new ArrayList<String>())
423             .addAllFilterControlIds(new ArrayList<String>())
424             .addAllRedirectControlIds(new ArrayList<String>())
425             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
426             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
427             .addAllDoNotAssociateControlIds(new ArrayList<String>())
428             .addAllReplacementControlIds(new ArrayList<String>())
429             .addAllIgnoreControlIds(new ArrayList<String>())
430             .setDiversityLevel("diversityLevel578206123")
431             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
432             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
433             .addAllSolutionTypes(new ArrayList<SolutionType>())
434             .build();
435     mockService.addResponse(expectedResponse);
436 
437     ServingConfigName name =
438         ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
439 
440     ServingConfig actualResponse = client.getServingConfig(name);
441     Assert.assertEquals(expectedResponse, actualResponse);
442 
443     List<String> actualRequests = mockService.getRequestPaths();
444     Assert.assertEquals(1, actualRequests.size());
445 
446     String apiClientHeaderKey =
447         mockService
448             .getRequestHeaders()
449             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
450             .iterator()
451             .next();
452     Assert.assertTrue(
453         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
454             .matcher(apiClientHeaderKey)
455             .matches());
456   }
457 
458   @Test
getServingConfigExceptionTest()459   public void getServingConfigExceptionTest() throws Exception {
460     ApiException exception =
461         ApiExceptionFactory.createException(
462             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
463     mockService.addException(exception);
464 
465     try {
466       ServingConfigName name =
467           ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
468       client.getServingConfig(name);
469       Assert.fail("No exception raised");
470     } catch (InvalidArgumentException e) {
471       // Expected exception.
472     }
473   }
474 
475   @Test
getServingConfigTest2()476   public void getServingConfigTest2() throws Exception {
477     ServingConfig expectedResponse =
478         ServingConfig.newBuilder()
479             .setName(
480                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
481                     .toString())
482             .setDisplayName("displayName1714148973")
483             .setModelId("modelId1226956324")
484             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
485             .addAllFacetControlIds(new ArrayList<String>())
486             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
487             .addAllBoostControlIds(new ArrayList<String>())
488             .addAllFilterControlIds(new ArrayList<String>())
489             .addAllRedirectControlIds(new ArrayList<String>())
490             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
491             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
492             .addAllDoNotAssociateControlIds(new ArrayList<String>())
493             .addAllReplacementControlIds(new ArrayList<String>())
494             .addAllIgnoreControlIds(new ArrayList<String>())
495             .setDiversityLevel("diversityLevel578206123")
496             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
497             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
498             .addAllSolutionTypes(new ArrayList<SolutionType>())
499             .build();
500     mockService.addResponse(expectedResponse);
501 
502     String name =
503         "projects/project-4507/locations/location-4507/catalogs/catalog-4507/servingConfigs/servingConfig-4507";
504 
505     ServingConfig actualResponse = client.getServingConfig(name);
506     Assert.assertEquals(expectedResponse, actualResponse);
507 
508     List<String> actualRequests = mockService.getRequestPaths();
509     Assert.assertEquals(1, actualRequests.size());
510 
511     String apiClientHeaderKey =
512         mockService
513             .getRequestHeaders()
514             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
515             .iterator()
516             .next();
517     Assert.assertTrue(
518         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
519             .matcher(apiClientHeaderKey)
520             .matches());
521   }
522 
523   @Test
getServingConfigExceptionTest2()524   public void getServingConfigExceptionTest2() throws Exception {
525     ApiException exception =
526         ApiExceptionFactory.createException(
527             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
528     mockService.addException(exception);
529 
530     try {
531       String name =
532           "projects/project-4507/locations/location-4507/catalogs/catalog-4507/servingConfigs/servingConfig-4507";
533       client.getServingConfig(name);
534       Assert.fail("No exception raised");
535     } catch (InvalidArgumentException e) {
536       // Expected exception.
537     }
538   }
539 
540   @Test
listServingConfigsTest()541   public void listServingConfigsTest() throws Exception {
542     ServingConfig responsesElement = ServingConfig.newBuilder().build();
543     ListServingConfigsResponse expectedResponse =
544         ListServingConfigsResponse.newBuilder()
545             .setNextPageToken("")
546             .addAllServingConfigs(Arrays.asList(responsesElement))
547             .build();
548     mockService.addResponse(expectedResponse);
549 
550     CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
551 
552     ListServingConfigsPagedResponse pagedListResponse = client.listServingConfigs(parent);
553 
554     List<ServingConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
555 
556     Assert.assertEquals(1, resources.size());
557     Assert.assertEquals(expectedResponse.getServingConfigsList().get(0), resources.get(0));
558 
559     List<String> actualRequests = mockService.getRequestPaths();
560     Assert.assertEquals(1, actualRequests.size());
561 
562     String apiClientHeaderKey =
563         mockService
564             .getRequestHeaders()
565             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
566             .iterator()
567             .next();
568     Assert.assertTrue(
569         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
570             .matcher(apiClientHeaderKey)
571             .matches());
572   }
573 
574   @Test
listServingConfigsExceptionTest()575   public void listServingConfigsExceptionTest() throws Exception {
576     ApiException exception =
577         ApiExceptionFactory.createException(
578             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
579     mockService.addException(exception);
580 
581     try {
582       CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
583       client.listServingConfigs(parent);
584       Assert.fail("No exception raised");
585     } catch (InvalidArgumentException e) {
586       // Expected exception.
587     }
588   }
589 
590   @Test
listServingConfigsTest2()591   public void listServingConfigsTest2() throws Exception {
592     ServingConfig responsesElement = ServingConfig.newBuilder().build();
593     ListServingConfigsResponse expectedResponse =
594         ListServingConfigsResponse.newBuilder()
595             .setNextPageToken("")
596             .addAllServingConfigs(Arrays.asList(responsesElement))
597             .build();
598     mockService.addResponse(expectedResponse);
599 
600     String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
601 
602     ListServingConfigsPagedResponse pagedListResponse = client.listServingConfigs(parent);
603 
604     List<ServingConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
605 
606     Assert.assertEquals(1, resources.size());
607     Assert.assertEquals(expectedResponse.getServingConfigsList().get(0), resources.get(0));
608 
609     List<String> actualRequests = mockService.getRequestPaths();
610     Assert.assertEquals(1, actualRequests.size());
611 
612     String apiClientHeaderKey =
613         mockService
614             .getRequestHeaders()
615             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
616             .iterator()
617             .next();
618     Assert.assertTrue(
619         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
620             .matcher(apiClientHeaderKey)
621             .matches());
622   }
623 
624   @Test
listServingConfigsExceptionTest2()625   public void listServingConfigsExceptionTest2() throws Exception {
626     ApiException exception =
627         ApiExceptionFactory.createException(
628             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
629     mockService.addException(exception);
630 
631     try {
632       String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267";
633       client.listServingConfigs(parent);
634       Assert.fail("No exception raised");
635     } catch (InvalidArgumentException e) {
636       // Expected exception.
637     }
638   }
639 
640   @Test
addControlTest()641   public void addControlTest() throws Exception {
642     ServingConfig expectedResponse =
643         ServingConfig.newBuilder()
644             .setName(
645                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
646                     .toString())
647             .setDisplayName("displayName1714148973")
648             .setModelId("modelId1226956324")
649             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
650             .addAllFacetControlIds(new ArrayList<String>())
651             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
652             .addAllBoostControlIds(new ArrayList<String>())
653             .addAllFilterControlIds(new ArrayList<String>())
654             .addAllRedirectControlIds(new ArrayList<String>())
655             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
656             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
657             .addAllDoNotAssociateControlIds(new ArrayList<String>())
658             .addAllReplacementControlIds(new ArrayList<String>())
659             .addAllIgnoreControlIds(new ArrayList<String>())
660             .setDiversityLevel("diversityLevel578206123")
661             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
662             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
663             .addAllSolutionTypes(new ArrayList<SolutionType>())
664             .build();
665     mockService.addResponse(expectedResponse);
666 
667     ServingConfigName servingConfig =
668         ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
669 
670     ServingConfig actualResponse = client.addControl(servingConfig);
671     Assert.assertEquals(expectedResponse, actualResponse);
672 
673     List<String> actualRequests = mockService.getRequestPaths();
674     Assert.assertEquals(1, actualRequests.size());
675 
676     String apiClientHeaderKey =
677         mockService
678             .getRequestHeaders()
679             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
680             .iterator()
681             .next();
682     Assert.assertTrue(
683         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
684             .matcher(apiClientHeaderKey)
685             .matches());
686   }
687 
688   @Test
addControlExceptionTest()689   public void addControlExceptionTest() throws Exception {
690     ApiException exception =
691         ApiExceptionFactory.createException(
692             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
693     mockService.addException(exception);
694 
695     try {
696       ServingConfigName servingConfig =
697           ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
698       client.addControl(servingConfig);
699       Assert.fail("No exception raised");
700     } catch (InvalidArgumentException e) {
701       // Expected exception.
702     }
703   }
704 
705   @Test
addControlTest2()706   public void addControlTest2() throws Exception {
707     ServingConfig expectedResponse =
708         ServingConfig.newBuilder()
709             .setName(
710                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
711                     .toString())
712             .setDisplayName("displayName1714148973")
713             .setModelId("modelId1226956324")
714             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
715             .addAllFacetControlIds(new ArrayList<String>())
716             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
717             .addAllBoostControlIds(new ArrayList<String>())
718             .addAllFilterControlIds(new ArrayList<String>())
719             .addAllRedirectControlIds(new ArrayList<String>())
720             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
721             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
722             .addAllDoNotAssociateControlIds(new ArrayList<String>())
723             .addAllReplacementControlIds(new ArrayList<String>())
724             .addAllIgnoreControlIds(new ArrayList<String>())
725             .setDiversityLevel("diversityLevel578206123")
726             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
727             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
728             .addAllSolutionTypes(new ArrayList<SolutionType>())
729             .build();
730     mockService.addResponse(expectedResponse);
731 
732     String servingConfig =
733         "projects/project-1064/locations/location-1064/catalogs/catalog-1064/servingConfigs/servingConfig-1064";
734 
735     ServingConfig actualResponse = client.addControl(servingConfig);
736     Assert.assertEquals(expectedResponse, actualResponse);
737 
738     List<String> actualRequests = mockService.getRequestPaths();
739     Assert.assertEquals(1, actualRequests.size());
740 
741     String apiClientHeaderKey =
742         mockService
743             .getRequestHeaders()
744             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
745             .iterator()
746             .next();
747     Assert.assertTrue(
748         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
749             .matcher(apiClientHeaderKey)
750             .matches());
751   }
752 
753   @Test
addControlExceptionTest2()754   public void addControlExceptionTest2() throws Exception {
755     ApiException exception =
756         ApiExceptionFactory.createException(
757             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
758     mockService.addException(exception);
759 
760     try {
761       String servingConfig =
762           "projects/project-1064/locations/location-1064/catalogs/catalog-1064/servingConfigs/servingConfig-1064";
763       client.addControl(servingConfig);
764       Assert.fail("No exception raised");
765     } catch (InvalidArgumentException e) {
766       // Expected exception.
767     }
768   }
769 
770   @Test
removeControlTest()771   public void removeControlTest() throws Exception {
772     ServingConfig expectedResponse =
773         ServingConfig.newBuilder()
774             .setName(
775                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
776                     .toString())
777             .setDisplayName("displayName1714148973")
778             .setModelId("modelId1226956324")
779             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
780             .addAllFacetControlIds(new ArrayList<String>())
781             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
782             .addAllBoostControlIds(new ArrayList<String>())
783             .addAllFilterControlIds(new ArrayList<String>())
784             .addAllRedirectControlIds(new ArrayList<String>())
785             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
786             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
787             .addAllDoNotAssociateControlIds(new ArrayList<String>())
788             .addAllReplacementControlIds(new ArrayList<String>())
789             .addAllIgnoreControlIds(new ArrayList<String>())
790             .setDiversityLevel("diversityLevel578206123")
791             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
792             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
793             .addAllSolutionTypes(new ArrayList<SolutionType>())
794             .build();
795     mockService.addResponse(expectedResponse);
796 
797     ServingConfigName servingConfig =
798         ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
799 
800     ServingConfig actualResponse = client.removeControl(servingConfig);
801     Assert.assertEquals(expectedResponse, actualResponse);
802 
803     List<String> actualRequests = mockService.getRequestPaths();
804     Assert.assertEquals(1, actualRequests.size());
805 
806     String apiClientHeaderKey =
807         mockService
808             .getRequestHeaders()
809             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
810             .iterator()
811             .next();
812     Assert.assertTrue(
813         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
814             .matcher(apiClientHeaderKey)
815             .matches());
816   }
817 
818   @Test
removeControlExceptionTest()819   public void removeControlExceptionTest() throws Exception {
820     ApiException exception =
821         ApiExceptionFactory.createException(
822             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
823     mockService.addException(exception);
824 
825     try {
826       ServingConfigName servingConfig =
827           ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]");
828       client.removeControl(servingConfig);
829       Assert.fail("No exception raised");
830     } catch (InvalidArgumentException e) {
831       // Expected exception.
832     }
833   }
834 
835   @Test
removeControlTest2()836   public void removeControlTest2() throws Exception {
837     ServingConfig expectedResponse =
838         ServingConfig.newBuilder()
839             .setName(
840                 ServingConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[SERVING_CONFIG]")
841                     .toString())
842             .setDisplayName("displayName1714148973")
843             .setModelId("modelId1226956324")
844             .setPriceRerankingLevel("priceRerankingLevel-1925548982")
845             .addAllFacetControlIds(new ArrayList<String>())
846             .setDynamicFacetSpec(SearchRequest.DynamicFacetSpec.newBuilder().build())
847             .addAllBoostControlIds(new ArrayList<String>())
848             .addAllFilterControlIds(new ArrayList<String>())
849             .addAllRedirectControlIds(new ArrayList<String>())
850             .addAllTwowaySynonymsControlIds(new ArrayList<String>())
851             .addAllOnewaySynonymsControlIds(new ArrayList<String>())
852             .addAllDoNotAssociateControlIds(new ArrayList<String>())
853             .addAllReplacementControlIds(new ArrayList<String>())
854             .addAllIgnoreControlIds(new ArrayList<String>())
855             .setDiversityLevel("diversityLevel578206123")
856             .setEnableCategoryFilterLevel("enableCategoryFilterLevel-1232535413")
857             .setPersonalizationSpec(SearchRequest.PersonalizationSpec.newBuilder().build())
858             .addAllSolutionTypes(new ArrayList<SolutionType>())
859             .build();
860     mockService.addResponse(expectedResponse);
861 
862     String servingConfig =
863         "projects/project-1064/locations/location-1064/catalogs/catalog-1064/servingConfigs/servingConfig-1064";
864 
865     ServingConfig actualResponse = client.removeControl(servingConfig);
866     Assert.assertEquals(expectedResponse, actualResponse);
867 
868     List<String> actualRequests = mockService.getRequestPaths();
869     Assert.assertEquals(1, actualRequests.size());
870 
871     String apiClientHeaderKey =
872         mockService
873             .getRequestHeaders()
874             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
875             .iterator()
876             .next();
877     Assert.assertTrue(
878         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
879             .matcher(apiClientHeaderKey)
880             .matches());
881   }
882 
883   @Test
removeControlExceptionTest2()884   public void removeControlExceptionTest2() throws Exception {
885     ApiException exception =
886         ApiExceptionFactory.createException(
887             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
888     mockService.addException(exception);
889 
890     try {
891       String servingConfig =
892           "projects/project-1064/locations/location-1064/catalogs/catalog-1064/servingConfigs/servingConfig-1064";
893       client.removeControl(servingConfig);
894       Assert.fail("No exception raised");
895     } catch (InvalidArgumentException e) {
896       // Expected exception.
897     }
898   }
899 }
900