• 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.enterpriseknowledgegraph.v1;
18 
19 import static com.google.cloud.enterpriseknowledgegraph.v1.EnterpriseKnowledgeGraphServiceClient.ListEntityReconciliationJobsPagedResponse;
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.enterpriseknowledgegraph.v1.stub.HttpJsonEnterpriseKnowledgeGraphServiceStub;
31 import com.google.common.collect.Lists;
32 import com.google.protobuf.Empty;
33 import com.google.protobuf.ListValue;
34 import com.google.protobuf.Timestamp;
35 import com.google.protobuf.Value;
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 javax.annotation.Generated;
42 import org.junit.After;
43 import org.junit.AfterClass;
44 import org.junit.Assert;
45 import org.junit.Before;
46 import org.junit.BeforeClass;
47 import org.junit.Test;
48 
49 @Generated("by gapic-generator-java")
50 public class EnterpriseKnowledgeGraphServiceClientHttpJsonTest {
51   private static MockHttpService mockService;
52   private static EnterpriseKnowledgeGraphServiceClient client;
53 
54   @BeforeClass
startStaticServer()55   public static void startStaticServer() throws IOException {
56     mockService =
57         new MockHttpService(
58             HttpJsonEnterpriseKnowledgeGraphServiceStub.getMethodDescriptors(),
59             EnterpriseKnowledgeGraphServiceSettings.getDefaultEndpoint());
60     EnterpriseKnowledgeGraphServiceSettings settings =
61         EnterpriseKnowledgeGraphServiceSettings.newHttpJsonBuilder()
62             .setTransportChannelProvider(
63                 EnterpriseKnowledgeGraphServiceSettings.defaultHttpJsonTransportProviderBuilder()
64                     .setHttpTransport(mockService)
65                     .build())
66             .setCredentialsProvider(NoCredentialsProvider.create())
67             .build();
68     client = EnterpriseKnowledgeGraphServiceClient.create(settings);
69   }
70 
71   @AfterClass
stopServer()72   public static void stopServer() {
73     client.close();
74   }
75 
76   @Before
setUp()77   public void setUp() {}
78 
79   @After
tearDown()80   public void tearDown() throws Exception {
81     mockService.reset();
82   }
83 
84   @Test
createEntityReconciliationJobTest()85   public void createEntityReconciliationJobTest() throws Exception {
86     EntityReconciliationJob expectedResponse =
87         EntityReconciliationJob.newBuilder()
88             .setName(
89                 EntityReconciliationJobName.of(
90                         "[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]")
91                     .toString())
92             .setInputConfig(InputConfig.newBuilder().build())
93             .setOutputConfig(OutputConfig.newBuilder().build())
94             .setState(JobState.forNumber(0))
95             .setError(Status.newBuilder().build())
96             .setCreateTime(Timestamp.newBuilder().build())
97             .setEndTime(Timestamp.newBuilder().build())
98             .setUpdateTime(Timestamp.newBuilder().build())
99             .setReconConfig(ReconConfig.newBuilder().build())
100             .build();
101     mockService.addResponse(expectedResponse);
102 
103     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
104     EntityReconciliationJob entityReconciliationJob = EntityReconciliationJob.newBuilder().build();
105 
106     EntityReconciliationJob actualResponse =
107         client.createEntityReconciliationJob(parent, entityReconciliationJob);
108     Assert.assertEquals(expectedResponse, actualResponse);
109 
110     List<String> actualRequests = mockService.getRequestPaths();
111     Assert.assertEquals(1, actualRequests.size());
112 
113     String apiClientHeaderKey =
114         mockService
115             .getRequestHeaders()
116             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
117             .iterator()
118             .next();
119     Assert.assertTrue(
120         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
121             .matcher(apiClientHeaderKey)
122             .matches());
123   }
124 
125   @Test
createEntityReconciliationJobExceptionTest()126   public void createEntityReconciliationJobExceptionTest() throws Exception {
127     ApiException exception =
128         ApiExceptionFactory.createException(
129             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
130     mockService.addException(exception);
131 
132     try {
133       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
134       EntityReconciliationJob entityReconciliationJob =
135           EntityReconciliationJob.newBuilder().build();
136       client.createEntityReconciliationJob(parent, entityReconciliationJob);
137       Assert.fail("No exception raised");
138     } catch (InvalidArgumentException e) {
139       // Expected exception.
140     }
141   }
142 
143   @Test
createEntityReconciliationJobTest2()144   public void createEntityReconciliationJobTest2() throws Exception {
145     EntityReconciliationJob expectedResponse =
146         EntityReconciliationJob.newBuilder()
147             .setName(
148                 EntityReconciliationJobName.of(
149                         "[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]")
150                     .toString())
151             .setInputConfig(InputConfig.newBuilder().build())
152             .setOutputConfig(OutputConfig.newBuilder().build())
153             .setState(JobState.forNumber(0))
154             .setError(Status.newBuilder().build())
155             .setCreateTime(Timestamp.newBuilder().build())
156             .setEndTime(Timestamp.newBuilder().build())
157             .setUpdateTime(Timestamp.newBuilder().build())
158             .setReconConfig(ReconConfig.newBuilder().build())
159             .build();
160     mockService.addResponse(expectedResponse);
161 
162     String parent = "projects/project-5833/locations/location-5833";
163     EntityReconciliationJob entityReconciliationJob = EntityReconciliationJob.newBuilder().build();
164 
165     EntityReconciliationJob actualResponse =
166         client.createEntityReconciliationJob(parent, entityReconciliationJob);
167     Assert.assertEquals(expectedResponse, actualResponse);
168 
169     List<String> actualRequests = mockService.getRequestPaths();
170     Assert.assertEquals(1, actualRequests.size());
171 
172     String apiClientHeaderKey =
173         mockService
174             .getRequestHeaders()
175             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
176             .iterator()
177             .next();
178     Assert.assertTrue(
179         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
180             .matcher(apiClientHeaderKey)
181             .matches());
182   }
183 
184   @Test
createEntityReconciliationJobExceptionTest2()185   public void createEntityReconciliationJobExceptionTest2() throws Exception {
186     ApiException exception =
187         ApiExceptionFactory.createException(
188             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
189     mockService.addException(exception);
190 
191     try {
192       String parent = "projects/project-5833/locations/location-5833";
193       EntityReconciliationJob entityReconciliationJob =
194           EntityReconciliationJob.newBuilder().build();
195       client.createEntityReconciliationJob(parent, entityReconciliationJob);
196       Assert.fail("No exception raised");
197     } catch (InvalidArgumentException e) {
198       // Expected exception.
199     }
200   }
201 
202   @Test
getEntityReconciliationJobTest()203   public void getEntityReconciliationJobTest() throws Exception {
204     EntityReconciliationJob expectedResponse =
205         EntityReconciliationJob.newBuilder()
206             .setName(
207                 EntityReconciliationJobName.of(
208                         "[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]")
209                     .toString())
210             .setInputConfig(InputConfig.newBuilder().build())
211             .setOutputConfig(OutputConfig.newBuilder().build())
212             .setState(JobState.forNumber(0))
213             .setError(Status.newBuilder().build())
214             .setCreateTime(Timestamp.newBuilder().build())
215             .setEndTime(Timestamp.newBuilder().build())
216             .setUpdateTime(Timestamp.newBuilder().build())
217             .setReconConfig(ReconConfig.newBuilder().build())
218             .build();
219     mockService.addResponse(expectedResponse);
220 
221     EntityReconciliationJobName name =
222         EntityReconciliationJobName.of("[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]");
223 
224     EntityReconciliationJob actualResponse = client.getEntityReconciliationJob(name);
225     Assert.assertEquals(expectedResponse, actualResponse);
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
getEntityReconciliationJobExceptionTest()243   public void getEntityReconciliationJobExceptionTest() 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       EntityReconciliationJobName name =
251           EntityReconciliationJobName.of("[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]");
252       client.getEntityReconciliationJob(name);
253       Assert.fail("No exception raised");
254     } catch (InvalidArgumentException e) {
255       // Expected exception.
256     }
257   }
258 
259   @Test
getEntityReconciliationJobTest2()260   public void getEntityReconciliationJobTest2() throws Exception {
261     EntityReconciliationJob expectedResponse =
262         EntityReconciliationJob.newBuilder()
263             .setName(
264                 EntityReconciliationJobName.of(
265                         "[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]")
266                     .toString())
267             .setInputConfig(InputConfig.newBuilder().build())
268             .setOutputConfig(OutputConfig.newBuilder().build())
269             .setState(JobState.forNumber(0))
270             .setError(Status.newBuilder().build())
271             .setCreateTime(Timestamp.newBuilder().build())
272             .setEndTime(Timestamp.newBuilder().build())
273             .setUpdateTime(Timestamp.newBuilder().build())
274             .setReconConfig(ReconConfig.newBuilder().build())
275             .build();
276     mockService.addResponse(expectedResponse);
277 
278     String name =
279         "projects/project-4188/locations/location-4188/entityReconciliationJobs/entityReconciliationJob-4188";
280 
281     EntityReconciliationJob actualResponse = client.getEntityReconciliationJob(name);
282     Assert.assertEquals(expectedResponse, actualResponse);
283 
284     List<String> actualRequests = mockService.getRequestPaths();
285     Assert.assertEquals(1, actualRequests.size());
286 
287     String apiClientHeaderKey =
288         mockService
289             .getRequestHeaders()
290             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
291             .iterator()
292             .next();
293     Assert.assertTrue(
294         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
295             .matcher(apiClientHeaderKey)
296             .matches());
297   }
298 
299   @Test
getEntityReconciliationJobExceptionTest2()300   public void getEntityReconciliationJobExceptionTest2() throws Exception {
301     ApiException exception =
302         ApiExceptionFactory.createException(
303             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
304     mockService.addException(exception);
305 
306     try {
307       String name =
308           "projects/project-4188/locations/location-4188/entityReconciliationJobs/entityReconciliationJob-4188";
309       client.getEntityReconciliationJob(name);
310       Assert.fail("No exception raised");
311     } catch (InvalidArgumentException e) {
312       // Expected exception.
313     }
314   }
315 
316   @Test
listEntityReconciliationJobsTest()317   public void listEntityReconciliationJobsTest() throws Exception {
318     EntityReconciliationJob responsesElement = EntityReconciliationJob.newBuilder().build();
319     ListEntityReconciliationJobsResponse expectedResponse =
320         ListEntityReconciliationJobsResponse.newBuilder()
321             .setNextPageToken("")
322             .addAllEntityReconciliationJobs(Arrays.asList(responsesElement))
323             .build();
324     mockService.addResponse(expectedResponse);
325 
326     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
327 
328     ListEntityReconciliationJobsPagedResponse pagedListResponse =
329         client.listEntityReconciliationJobs(parent);
330 
331     List<EntityReconciliationJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
332 
333     Assert.assertEquals(1, resources.size());
334     Assert.assertEquals(
335         expectedResponse.getEntityReconciliationJobsList().get(0), resources.get(0));
336 
337     List<String> actualRequests = mockService.getRequestPaths();
338     Assert.assertEquals(1, actualRequests.size());
339 
340     String apiClientHeaderKey =
341         mockService
342             .getRequestHeaders()
343             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
344             .iterator()
345             .next();
346     Assert.assertTrue(
347         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
348             .matcher(apiClientHeaderKey)
349             .matches());
350   }
351 
352   @Test
listEntityReconciliationJobsExceptionTest()353   public void listEntityReconciliationJobsExceptionTest() throws Exception {
354     ApiException exception =
355         ApiExceptionFactory.createException(
356             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
357     mockService.addException(exception);
358 
359     try {
360       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
361       client.listEntityReconciliationJobs(parent);
362       Assert.fail("No exception raised");
363     } catch (InvalidArgumentException e) {
364       // Expected exception.
365     }
366   }
367 
368   @Test
listEntityReconciliationJobsTest2()369   public void listEntityReconciliationJobsTest2() throws Exception {
370     EntityReconciliationJob responsesElement = EntityReconciliationJob.newBuilder().build();
371     ListEntityReconciliationJobsResponse expectedResponse =
372         ListEntityReconciliationJobsResponse.newBuilder()
373             .setNextPageToken("")
374             .addAllEntityReconciliationJobs(Arrays.asList(responsesElement))
375             .build();
376     mockService.addResponse(expectedResponse);
377 
378     String parent = "projects/project-5833/locations/location-5833";
379 
380     ListEntityReconciliationJobsPagedResponse pagedListResponse =
381         client.listEntityReconciliationJobs(parent);
382 
383     List<EntityReconciliationJob> resources = Lists.newArrayList(pagedListResponse.iterateAll());
384 
385     Assert.assertEquals(1, resources.size());
386     Assert.assertEquals(
387         expectedResponse.getEntityReconciliationJobsList().get(0), resources.get(0));
388 
389     List<String> actualRequests = mockService.getRequestPaths();
390     Assert.assertEquals(1, actualRequests.size());
391 
392     String apiClientHeaderKey =
393         mockService
394             .getRequestHeaders()
395             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
396             .iterator()
397             .next();
398     Assert.assertTrue(
399         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
400             .matcher(apiClientHeaderKey)
401             .matches());
402   }
403 
404   @Test
listEntityReconciliationJobsExceptionTest2()405   public void listEntityReconciliationJobsExceptionTest2() throws Exception {
406     ApiException exception =
407         ApiExceptionFactory.createException(
408             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
409     mockService.addException(exception);
410 
411     try {
412       String parent = "projects/project-5833/locations/location-5833";
413       client.listEntityReconciliationJobs(parent);
414       Assert.fail("No exception raised");
415     } catch (InvalidArgumentException e) {
416       // Expected exception.
417     }
418   }
419 
420   @Test
cancelEntityReconciliationJobTest()421   public void cancelEntityReconciliationJobTest() throws Exception {
422     Empty expectedResponse = Empty.newBuilder().build();
423     mockService.addResponse(expectedResponse);
424 
425     EntityReconciliationJobName name =
426         EntityReconciliationJobName.of("[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]");
427 
428     client.cancelEntityReconciliationJob(name);
429 
430     List<String> actualRequests = mockService.getRequestPaths();
431     Assert.assertEquals(1, actualRequests.size());
432 
433     String apiClientHeaderKey =
434         mockService
435             .getRequestHeaders()
436             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
437             .iterator()
438             .next();
439     Assert.assertTrue(
440         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
441             .matcher(apiClientHeaderKey)
442             .matches());
443   }
444 
445   @Test
cancelEntityReconciliationJobExceptionTest()446   public void cancelEntityReconciliationJobExceptionTest() throws Exception {
447     ApiException exception =
448         ApiExceptionFactory.createException(
449             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
450     mockService.addException(exception);
451 
452     try {
453       EntityReconciliationJobName name =
454           EntityReconciliationJobName.of("[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]");
455       client.cancelEntityReconciliationJob(name);
456       Assert.fail("No exception raised");
457     } catch (InvalidArgumentException e) {
458       // Expected exception.
459     }
460   }
461 
462   @Test
cancelEntityReconciliationJobTest2()463   public void cancelEntityReconciliationJobTest2() throws Exception {
464     Empty expectedResponse = Empty.newBuilder().build();
465     mockService.addResponse(expectedResponse);
466 
467     String name =
468         "projects/project-4188/locations/location-4188/entityReconciliationJobs/entityReconciliationJob-4188";
469 
470     client.cancelEntityReconciliationJob(name);
471 
472     List<String> actualRequests = mockService.getRequestPaths();
473     Assert.assertEquals(1, actualRequests.size());
474 
475     String apiClientHeaderKey =
476         mockService
477             .getRequestHeaders()
478             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
479             .iterator()
480             .next();
481     Assert.assertTrue(
482         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
483             .matcher(apiClientHeaderKey)
484             .matches());
485   }
486 
487   @Test
cancelEntityReconciliationJobExceptionTest2()488   public void cancelEntityReconciliationJobExceptionTest2() throws Exception {
489     ApiException exception =
490         ApiExceptionFactory.createException(
491             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
492     mockService.addException(exception);
493 
494     try {
495       String name =
496           "projects/project-4188/locations/location-4188/entityReconciliationJobs/entityReconciliationJob-4188";
497       client.cancelEntityReconciliationJob(name);
498       Assert.fail("No exception raised");
499     } catch (InvalidArgumentException e) {
500       // Expected exception.
501     }
502   }
503 
504   @Test
deleteEntityReconciliationJobTest()505   public void deleteEntityReconciliationJobTest() throws Exception {
506     Empty expectedResponse = Empty.newBuilder().build();
507     mockService.addResponse(expectedResponse);
508 
509     EntityReconciliationJobName name =
510         EntityReconciliationJobName.of("[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]");
511 
512     client.deleteEntityReconciliationJob(name);
513 
514     List<String> actualRequests = mockService.getRequestPaths();
515     Assert.assertEquals(1, actualRequests.size());
516 
517     String apiClientHeaderKey =
518         mockService
519             .getRequestHeaders()
520             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
521             .iterator()
522             .next();
523     Assert.assertTrue(
524         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
525             .matcher(apiClientHeaderKey)
526             .matches());
527   }
528 
529   @Test
deleteEntityReconciliationJobExceptionTest()530   public void deleteEntityReconciliationJobExceptionTest() throws Exception {
531     ApiException exception =
532         ApiExceptionFactory.createException(
533             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
534     mockService.addException(exception);
535 
536     try {
537       EntityReconciliationJobName name =
538           EntityReconciliationJobName.of("[PROJECT]", "[LOCATION]", "[ENTITY_RECONCILIATION_JOB]");
539       client.deleteEntityReconciliationJob(name);
540       Assert.fail("No exception raised");
541     } catch (InvalidArgumentException e) {
542       // Expected exception.
543     }
544   }
545 
546   @Test
deleteEntityReconciliationJobTest2()547   public void deleteEntityReconciliationJobTest2() throws Exception {
548     Empty expectedResponse = Empty.newBuilder().build();
549     mockService.addResponse(expectedResponse);
550 
551     String name =
552         "projects/project-4188/locations/location-4188/entityReconciliationJobs/entityReconciliationJob-4188";
553 
554     client.deleteEntityReconciliationJob(name);
555 
556     List<String> actualRequests = mockService.getRequestPaths();
557     Assert.assertEquals(1, actualRequests.size());
558 
559     String apiClientHeaderKey =
560         mockService
561             .getRequestHeaders()
562             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
563             .iterator()
564             .next();
565     Assert.assertTrue(
566         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
567             .matcher(apiClientHeaderKey)
568             .matches());
569   }
570 
571   @Test
deleteEntityReconciliationJobExceptionTest2()572   public void deleteEntityReconciliationJobExceptionTest2() throws Exception {
573     ApiException exception =
574         ApiExceptionFactory.createException(
575             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
576     mockService.addException(exception);
577 
578     try {
579       String name =
580           "projects/project-4188/locations/location-4188/entityReconciliationJobs/entityReconciliationJob-4188";
581       client.deleteEntityReconciliationJob(name);
582       Assert.fail("No exception raised");
583     } catch (InvalidArgumentException e) {
584       // Expected exception.
585     }
586   }
587 
588   @Test
lookupTest()589   public void lookupTest() throws Exception {
590     LookupResponse expectedResponse =
591         LookupResponse.newBuilder()
592             .setContext(Value.newBuilder().setBoolValue(true).build())
593             .setType(Value.newBuilder().setBoolValue(true).build())
594             .setItemListElement(ListValue.newBuilder().build())
595             .build();
596     mockService.addResponse(expectedResponse);
597 
598     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
599     List<String> ids = new ArrayList<>();
600 
601     LookupResponse actualResponse = client.lookup(parent, ids);
602     Assert.assertEquals(expectedResponse, actualResponse);
603 
604     List<String> actualRequests = mockService.getRequestPaths();
605     Assert.assertEquals(1, actualRequests.size());
606 
607     String apiClientHeaderKey =
608         mockService
609             .getRequestHeaders()
610             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
611             .iterator()
612             .next();
613     Assert.assertTrue(
614         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
615             .matcher(apiClientHeaderKey)
616             .matches());
617   }
618 
619   @Test
lookupExceptionTest()620   public void lookupExceptionTest() throws Exception {
621     ApiException exception =
622         ApiExceptionFactory.createException(
623             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
624     mockService.addException(exception);
625 
626     try {
627       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
628       List<String> ids = new ArrayList<>();
629       client.lookup(parent, ids);
630       Assert.fail("No exception raised");
631     } catch (InvalidArgumentException e) {
632       // Expected exception.
633     }
634   }
635 
636   @Test
lookupTest2()637   public void lookupTest2() throws Exception {
638     LookupResponse expectedResponse =
639         LookupResponse.newBuilder()
640             .setContext(Value.newBuilder().setBoolValue(true).build())
641             .setType(Value.newBuilder().setBoolValue(true).build())
642             .setItemListElement(ListValue.newBuilder().build())
643             .build();
644     mockService.addResponse(expectedResponse);
645 
646     String parent = "projects/project-5833/locations/location-5833";
647     List<String> ids = new ArrayList<>();
648 
649     LookupResponse actualResponse = client.lookup(parent, ids);
650     Assert.assertEquals(expectedResponse, actualResponse);
651 
652     List<String> actualRequests = mockService.getRequestPaths();
653     Assert.assertEquals(1, actualRequests.size());
654 
655     String apiClientHeaderKey =
656         mockService
657             .getRequestHeaders()
658             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
659             .iterator()
660             .next();
661     Assert.assertTrue(
662         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
663             .matcher(apiClientHeaderKey)
664             .matches());
665   }
666 
667   @Test
lookupExceptionTest2()668   public void lookupExceptionTest2() throws Exception {
669     ApiException exception =
670         ApiExceptionFactory.createException(
671             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
672     mockService.addException(exception);
673 
674     try {
675       String parent = "projects/project-5833/locations/location-5833";
676       List<String> ids = new ArrayList<>();
677       client.lookup(parent, ids);
678       Assert.fail("No exception raised");
679     } catch (InvalidArgumentException e) {
680       // Expected exception.
681     }
682   }
683 
684   @Test
searchTest()685   public void searchTest() throws Exception {
686     SearchResponse expectedResponse =
687         SearchResponse.newBuilder()
688             .setContext(Value.newBuilder().setBoolValue(true).build())
689             .setType(Value.newBuilder().setBoolValue(true).build())
690             .setItemListElement(ListValue.newBuilder().build())
691             .build();
692     mockService.addResponse(expectedResponse);
693 
694     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
695     String query = "query107944136";
696 
697     SearchResponse actualResponse = client.search(parent, query);
698     Assert.assertEquals(expectedResponse, actualResponse);
699 
700     List<String> actualRequests = mockService.getRequestPaths();
701     Assert.assertEquals(1, actualRequests.size());
702 
703     String apiClientHeaderKey =
704         mockService
705             .getRequestHeaders()
706             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
707             .iterator()
708             .next();
709     Assert.assertTrue(
710         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
711             .matcher(apiClientHeaderKey)
712             .matches());
713   }
714 
715   @Test
searchExceptionTest()716   public void searchExceptionTest() throws Exception {
717     ApiException exception =
718         ApiExceptionFactory.createException(
719             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
720     mockService.addException(exception);
721 
722     try {
723       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
724       String query = "query107944136";
725       client.search(parent, query);
726       Assert.fail("No exception raised");
727     } catch (InvalidArgumentException e) {
728       // Expected exception.
729     }
730   }
731 
732   @Test
searchTest2()733   public void searchTest2() throws Exception {
734     SearchResponse expectedResponse =
735         SearchResponse.newBuilder()
736             .setContext(Value.newBuilder().setBoolValue(true).build())
737             .setType(Value.newBuilder().setBoolValue(true).build())
738             .setItemListElement(ListValue.newBuilder().build())
739             .build();
740     mockService.addResponse(expectedResponse);
741 
742     String parent = "projects/project-5833/locations/location-5833";
743     String query = "query107944136";
744 
745     SearchResponse actualResponse = client.search(parent, query);
746     Assert.assertEquals(expectedResponse, actualResponse);
747 
748     List<String> actualRequests = mockService.getRequestPaths();
749     Assert.assertEquals(1, actualRequests.size());
750 
751     String apiClientHeaderKey =
752         mockService
753             .getRequestHeaders()
754             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
755             .iterator()
756             .next();
757     Assert.assertTrue(
758         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
759             .matcher(apiClientHeaderKey)
760             .matches());
761   }
762 
763   @Test
searchExceptionTest2()764   public void searchExceptionTest2() throws Exception {
765     ApiException exception =
766         ApiExceptionFactory.createException(
767             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
768     mockService.addException(exception);
769 
770     try {
771       String parent = "projects/project-5833/locations/location-5833";
772       String query = "query107944136";
773       client.search(parent, query);
774       Assert.fail("No exception raised");
775     } catch (InvalidArgumentException e) {
776       // Expected exception.
777     }
778   }
779 
780   @Test
lookupPublicKgTest()781   public void lookupPublicKgTest() throws Exception {
782     LookupPublicKgResponse expectedResponse =
783         LookupPublicKgResponse.newBuilder()
784             .setContext(Value.newBuilder().setBoolValue(true).build())
785             .setType(Value.newBuilder().setBoolValue(true).build())
786             .setItemListElement(ListValue.newBuilder().build())
787             .build();
788     mockService.addResponse(expectedResponse);
789 
790     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
791     List<String> ids = new ArrayList<>();
792 
793     LookupPublicKgResponse actualResponse = client.lookupPublicKg(parent, ids);
794     Assert.assertEquals(expectedResponse, actualResponse);
795 
796     List<String> actualRequests = mockService.getRequestPaths();
797     Assert.assertEquals(1, actualRequests.size());
798 
799     String apiClientHeaderKey =
800         mockService
801             .getRequestHeaders()
802             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
803             .iterator()
804             .next();
805     Assert.assertTrue(
806         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
807             .matcher(apiClientHeaderKey)
808             .matches());
809   }
810 
811   @Test
lookupPublicKgExceptionTest()812   public void lookupPublicKgExceptionTest() throws Exception {
813     ApiException exception =
814         ApiExceptionFactory.createException(
815             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
816     mockService.addException(exception);
817 
818     try {
819       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
820       List<String> ids = new ArrayList<>();
821       client.lookupPublicKg(parent, ids);
822       Assert.fail("No exception raised");
823     } catch (InvalidArgumentException e) {
824       // Expected exception.
825     }
826   }
827 
828   @Test
lookupPublicKgTest2()829   public void lookupPublicKgTest2() throws Exception {
830     LookupPublicKgResponse expectedResponse =
831         LookupPublicKgResponse.newBuilder()
832             .setContext(Value.newBuilder().setBoolValue(true).build())
833             .setType(Value.newBuilder().setBoolValue(true).build())
834             .setItemListElement(ListValue.newBuilder().build())
835             .build();
836     mockService.addResponse(expectedResponse);
837 
838     String parent = "projects/project-5833/locations/location-5833";
839     List<String> ids = new ArrayList<>();
840 
841     LookupPublicKgResponse actualResponse = client.lookupPublicKg(parent, ids);
842     Assert.assertEquals(expectedResponse, actualResponse);
843 
844     List<String> actualRequests = mockService.getRequestPaths();
845     Assert.assertEquals(1, actualRequests.size());
846 
847     String apiClientHeaderKey =
848         mockService
849             .getRequestHeaders()
850             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
851             .iterator()
852             .next();
853     Assert.assertTrue(
854         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
855             .matcher(apiClientHeaderKey)
856             .matches());
857   }
858 
859   @Test
lookupPublicKgExceptionTest2()860   public void lookupPublicKgExceptionTest2() throws Exception {
861     ApiException exception =
862         ApiExceptionFactory.createException(
863             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
864     mockService.addException(exception);
865 
866     try {
867       String parent = "projects/project-5833/locations/location-5833";
868       List<String> ids = new ArrayList<>();
869       client.lookupPublicKg(parent, ids);
870       Assert.fail("No exception raised");
871     } catch (InvalidArgumentException e) {
872       // Expected exception.
873     }
874   }
875 
876   @Test
searchPublicKgTest()877   public void searchPublicKgTest() throws Exception {
878     SearchPublicKgResponse expectedResponse =
879         SearchPublicKgResponse.newBuilder()
880             .setContext(Value.newBuilder().setBoolValue(true).build())
881             .setType(Value.newBuilder().setBoolValue(true).build())
882             .setItemListElement(ListValue.newBuilder().build())
883             .build();
884     mockService.addResponse(expectedResponse);
885 
886     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
887     String query = "query107944136";
888 
889     SearchPublicKgResponse actualResponse = client.searchPublicKg(parent, query);
890     Assert.assertEquals(expectedResponse, actualResponse);
891 
892     List<String> actualRequests = mockService.getRequestPaths();
893     Assert.assertEquals(1, actualRequests.size());
894 
895     String apiClientHeaderKey =
896         mockService
897             .getRequestHeaders()
898             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
899             .iterator()
900             .next();
901     Assert.assertTrue(
902         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
903             .matcher(apiClientHeaderKey)
904             .matches());
905   }
906 
907   @Test
searchPublicKgExceptionTest()908   public void searchPublicKgExceptionTest() throws Exception {
909     ApiException exception =
910         ApiExceptionFactory.createException(
911             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
912     mockService.addException(exception);
913 
914     try {
915       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
916       String query = "query107944136";
917       client.searchPublicKg(parent, query);
918       Assert.fail("No exception raised");
919     } catch (InvalidArgumentException e) {
920       // Expected exception.
921     }
922   }
923 
924   @Test
searchPublicKgTest2()925   public void searchPublicKgTest2() throws Exception {
926     SearchPublicKgResponse expectedResponse =
927         SearchPublicKgResponse.newBuilder()
928             .setContext(Value.newBuilder().setBoolValue(true).build())
929             .setType(Value.newBuilder().setBoolValue(true).build())
930             .setItemListElement(ListValue.newBuilder().build())
931             .build();
932     mockService.addResponse(expectedResponse);
933 
934     String parent = "projects/project-5833/locations/location-5833";
935     String query = "query107944136";
936 
937     SearchPublicKgResponse actualResponse = client.searchPublicKg(parent, query);
938     Assert.assertEquals(expectedResponse, actualResponse);
939 
940     List<String> actualRequests = mockService.getRequestPaths();
941     Assert.assertEquals(1, actualRequests.size());
942 
943     String apiClientHeaderKey =
944         mockService
945             .getRequestHeaders()
946             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
947             .iterator()
948             .next();
949     Assert.assertTrue(
950         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
951             .matcher(apiClientHeaderKey)
952             .matches());
953   }
954 
955   @Test
searchPublicKgExceptionTest2()956   public void searchPublicKgExceptionTest2() throws Exception {
957     ApiException exception =
958         ApiExceptionFactory.createException(
959             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
960     mockService.addException(exception);
961 
962     try {
963       String parent = "projects/project-5833/locations/location-5833";
964       String query = "query107944136";
965       client.searchPublicKg(parent, query);
966       Assert.fail("No exception raised");
967     } catch (InvalidArgumentException e) {
968       // Expected exception.
969     }
970   }
971 }
972