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