• 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.contentwarehouse.v1;
18 
19 import static com.google.cloud.contentwarehouse.v1.DocumentServiceClient.SearchDocumentsPagedResponse;
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.contentwarehouse.v1.stub.HttpJsonDocumentServiceStub;
31 import com.google.common.collect.Lists;
32 import com.google.iam.v1.Policy;
33 import com.google.longrunning.Operation;
34 import com.google.protobuf.Empty;
35 import com.google.protobuf.Timestamp;
36 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.List;
40 import javax.annotation.Generated;
41 import org.junit.After;
42 import org.junit.AfterClass;
43 import org.junit.Assert;
44 import org.junit.Before;
45 import org.junit.BeforeClass;
46 import org.junit.Test;
47 
48 @Generated("by gapic-generator-java")
49 public class DocumentServiceClientHttpJsonTest {
50   private static MockHttpService mockService;
51   private static DocumentServiceClient client;
52 
53   @BeforeClass
startStaticServer()54   public static void startStaticServer() throws IOException {
55     mockService =
56         new MockHttpService(
57             HttpJsonDocumentServiceStub.getMethodDescriptors(),
58             DocumentServiceSettings.getDefaultEndpoint());
59     DocumentServiceSettings settings =
60         DocumentServiceSettings.newHttpJsonBuilder()
61             .setTransportChannelProvider(
62                 DocumentServiceSettings.defaultHttpJsonTransportProviderBuilder()
63                     .setHttpTransport(mockService)
64                     .build())
65             .setCredentialsProvider(NoCredentialsProvider.create())
66             .build();
67     client = DocumentServiceClient.create(settings);
68   }
69 
70   @AfterClass
stopServer()71   public static void stopServer() {
72     client.close();
73   }
74 
75   @Before
setUp()76   public void setUp() {}
77 
78   @After
tearDown()79   public void tearDown() throws Exception {
80     mockService.reset();
81   }
82 
83   @Test
createDocumentTest()84   public void createDocumentTest() throws Exception {
85     CreateDocumentResponse expectedResponse =
86         CreateDocumentResponse.newBuilder()
87             .setDocument(Document.newBuilder().build())
88             .setRuleEngineOutput(RuleEngineOutput.newBuilder().build())
89             .setMetadata(ResponseMetadata.newBuilder().build())
90             .addAllLongRunningOperations(new ArrayList<Operation>())
91             .build();
92     mockService.addResponse(expectedResponse);
93 
94     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
95     Document document = Document.newBuilder().build();
96 
97     CreateDocumentResponse actualResponse = client.createDocument(parent, document);
98     Assert.assertEquals(expectedResponse, actualResponse);
99 
100     List<String> actualRequests = mockService.getRequestPaths();
101     Assert.assertEquals(1, actualRequests.size());
102 
103     String apiClientHeaderKey =
104         mockService
105             .getRequestHeaders()
106             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
107             .iterator()
108             .next();
109     Assert.assertTrue(
110         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
111             .matcher(apiClientHeaderKey)
112             .matches());
113   }
114 
115   @Test
createDocumentExceptionTest()116   public void createDocumentExceptionTest() throws Exception {
117     ApiException exception =
118         ApiExceptionFactory.createException(
119             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
120     mockService.addException(exception);
121 
122     try {
123       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
124       Document document = Document.newBuilder().build();
125       client.createDocument(parent, document);
126       Assert.fail("No exception raised");
127     } catch (InvalidArgumentException e) {
128       // Expected exception.
129     }
130   }
131 
132   @Test
createDocumentTest2()133   public void createDocumentTest2() throws Exception {
134     CreateDocumentResponse expectedResponse =
135         CreateDocumentResponse.newBuilder()
136             .setDocument(Document.newBuilder().build())
137             .setRuleEngineOutput(RuleEngineOutput.newBuilder().build())
138             .setMetadata(ResponseMetadata.newBuilder().build())
139             .addAllLongRunningOperations(new ArrayList<Operation>())
140             .build();
141     mockService.addResponse(expectedResponse);
142 
143     String parent = "projects/project-5833/locations/location-5833";
144     Document document = Document.newBuilder().build();
145 
146     CreateDocumentResponse actualResponse = client.createDocument(parent, document);
147     Assert.assertEquals(expectedResponse, actualResponse);
148 
149     List<String> actualRequests = mockService.getRequestPaths();
150     Assert.assertEquals(1, actualRequests.size());
151 
152     String apiClientHeaderKey =
153         mockService
154             .getRequestHeaders()
155             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
156             .iterator()
157             .next();
158     Assert.assertTrue(
159         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
160             .matcher(apiClientHeaderKey)
161             .matches());
162   }
163 
164   @Test
createDocumentExceptionTest2()165   public void createDocumentExceptionTest2() throws Exception {
166     ApiException exception =
167         ApiExceptionFactory.createException(
168             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
169     mockService.addException(exception);
170 
171     try {
172       String parent = "projects/project-5833/locations/location-5833";
173       Document document = Document.newBuilder().build();
174       client.createDocument(parent, document);
175       Assert.fail("No exception raised");
176     } catch (InvalidArgumentException e) {
177       // Expected exception.
178     }
179   }
180 
181   @Test
getDocumentTest()182   public void getDocumentTest() throws Exception {
183     Document expectedResponse =
184         Document.newBuilder()
185             .setName(
186                 DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]")
187                     .toString())
188             .setReferenceId("referenceId-16211514")
189             .setDisplayName("displayName1714148973")
190             .setTitle("title110371416")
191             .setDisplayUri("displayUri-914528950")
192             .setDocumentSchemaName(
193                 DocumentSchemaName.of("[PROJECT]", "[LOCATION]", "[DOCUMENT_SCHEMA]").toString())
194             .setStructuredContentUri("structuredContentUri-1039251868")
195             .addAllProperties(new ArrayList<Property>())
196             .setUpdateTime(Timestamp.newBuilder().build())
197             .setCreateTime(Timestamp.newBuilder().build())
198             .setRawDocumentFileType(RawDocumentFileType.forNumber(0))
199             .setAsyncEnabled(true)
200             .setContentCategory(ContentCategory.forNumber(0))
201             .setTextExtractionDisabled(true)
202             .setTextExtractionEnabled(true)
203             .setCreator("creator1028554796")
204             .setUpdater("updater-234430263")
205             .build();
206     mockService.addResponse(expectedResponse);
207 
208     DocumentName name =
209         DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
210 
211     Document actualResponse = client.getDocument(name);
212     Assert.assertEquals(expectedResponse, actualResponse);
213 
214     List<String> actualRequests = mockService.getRequestPaths();
215     Assert.assertEquals(1, actualRequests.size());
216 
217     String apiClientHeaderKey =
218         mockService
219             .getRequestHeaders()
220             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
221             .iterator()
222             .next();
223     Assert.assertTrue(
224         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
225             .matcher(apiClientHeaderKey)
226             .matches());
227   }
228 
229   @Test
getDocumentExceptionTest()230   public void getDocumentExceptionTest() throws Exception {
231     ApiException exception =
232         ApiExceptionFactory.createException(
233             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
234     mockService.addException(exception);
235 
236     try {
237       DocumentName name =
238           DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
239       client.getDocument(name);
240       Assert.fail("No exception raised");
241     } catch (InvalidArgumentException e) {
242       // Expected exception.
243     }
244   }
245 
246   @Test
getDocumentTest2()247   public void getDocumentTest2() throws Exception {
248     Document expectedResponse =
249         Document.newBuilder()
250             .setName(
251                 DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]")
252                     .toString())
253             .setReferenceId("referenceId-16211514")
254             .setDisplayName("displayName1714148973")
255             .setTitle("title110371416")
256             .setDisplayUri("displayUri-914528950")
257             .setDocumentSchemaName(
258                 DocumentSchemaName.of("[PROJECT]", "[LOCATION]", "[DOCUMENT_SCHEMA]").toString())
259             .setStructuredContentUri("structuredContentUri-1039251868")
260             .addAllProperties(new ArrayList<Property>())
261             .setUpdateTime(Timestamp.newBuilder().build())
262             .setCreateTime(Timestamp.newBuilder().build())
263             .setRawDocumentFileType(RawDocumentFileType.forNumber(0))
264             .setAsyncEnabled(true)
265             .setContentCategory(ContentCategory.forNumber(0))
266             .setTextExtractionDisabled(true)
267             .setTextExtractionEnabled(true)
268             .setCreator("creator1028554796")
269             .setUpdater("updater-234430263")
270             .build();
271     mockService.addResponse(expectedResponse);
272 
273     String name = "projects/project-5698/locations/location-5698/documents/document-5698";
274 
275     Document actualResponse = client.getDocument(name);
276     Assert.assertEquals(expectedResponse, actualResponse);
277 
278     List<String> actualRequests = mockService.getRequestPaths();
279     Assert.assertEquals(1, actualRequests.size());
280 
281     String apiClientHeaderKey =
282         mockService
283             .getRequestHeaders()
284             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
285             .iterator()
286             .next();
287     Assert.assertTrue(
288         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
289             .matcher(apiClientHeaderKey)
290             .matches());
291   }
292 
293   @Test
getDocumentExceptionTest2()294   public void getDocumentExceptionTest2() throws Exception {
295     ApiException exception =
296         ApiExceptionFactory.createException(
297             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
298     mockService.addException(exception);
299 
300     try {
301       String name = "projects/project-5698/locations/location-5698/documents/document-5698";
302       client.getDocument(name);
303       Assert.fail("No exception raised");
304     } catch (InvalidArgumentException e) {
305       // Expected exception.
306     }
307   }
308 
309   @Test
updateDocumentTest()310   public void updateDocumentTest() throws Exception {
311     UpdateDocumentResponse expectedResponse =
312         UpdateDocumentResponse.newBuilder()
313             .setDocument(Document.newBuilder().build())
314             .setRuleEngineOutput(RuleEngineOutput.newBuilder().build())
315             .setMetadata(ResponseMetadata.newBuilder().build())
316             .build();
317     mockService.addResponse(expectedResponse);
318 
319     DocumentName name =
320         DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
321     Document document = Document.newBuilder().build();
322 
323     UpdateDocumentResponse actualResponse = client.updateDocument(name, document);
324     Assert.assertEquals(expectedResponse, actualResponse);
325 
326     List<String> actualRequests = mockService.getRequestPaths();
327     Assert.assertEquals(1, actualRequests.size());
328 
329     String apiClientHeaderKey =
330         mockService
331             .getRequestHeaders()
332             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
333             .iterator()
334             .next();
335     Assert.assertTrue(
336         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
337             .matcher(apiClientHeaderKey)
338             .matches());
339   }
340 
341   @Test
updateDocumentExceptionTest()342   public void updateDocumentExceptionTest() throws Exception {
343     ApiException exception =
344         ApiExceptionFactory.createException(
345             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
346     mockService.addException(exception);
347 
348     try {
349       DocumentName name =
350           DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
351       Document document = Document.newBuilder().build();
352       client.updateDocument(name, document);
353       Assert.fail("No exception raised");
354     } catch (InvalidArgumentException e) {
355       // Expected exception.
356     }
357   }
358 
359   @Test
updateDocumentTest2()360   public void updateDocumentTest2() throws Exception {
361     UpdateDocumentResponse expectedResponse =
362         UpdateDocumentResponse.newBuilder()
363             .setDocument(Document.newBuilder().build())
364             .setRuleEngineOutput(RuleEngineOutput.newBuilder().build())
365             .setMetadata(ResponseMetadata.newBuilder().build())
366             .build();
367     mockService.addResponse(expectedResponse);
368 
369     String name = "projects/project-5698/locations/location-5698/documents/document-5698";
370     Document document = Document.newBuilder().build();
371 
372     UpdateDocumentResponse actualResponse = client.updateDocument(name, document);
373     Assert.assertEquals(expectedResponse, actualResponse);
374 
375     List<String> actualRequests = mockService.getRequestPaths();
376     Assert.assertEquals(1, actualRequests.size());
377 
378     String apiClientHeaderKey =
379         mockService
380             .getRequestHeaders()
381             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
382             .iterator()
383             .next();
384     Assert.assertTrue(
385         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
386             .matcher(apiClientHeaderKey)
387             .matches());
388   }
389 
390   @Test
updateDocumentExceptionTest2()391   public void updateDocumentExceptionTest2() throws Exception {
392     ApiException exception =
393         ApiExceptionFactory.createException(
394             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
395     mockService.addException(exception);
396 
397     try {
398       String name = "projects/project-5698/locations/location-5698/documents/document-5698";
399       Document document = Document.newBuilder().build();
400       client.updateDocument(name, document);
401       Assert.fail("No exception raised");
402     } catch (InvalidArgumentException e) {
403       // Expected exception.
404     }
405   }
406 
407   @Test
deleteDocumentTest()408   public void deleteDocumentTest() throws Exception {
409     Empty expectedResponse = Empty.newBuilder().build();
410     mockService.addResponse(expectedResponse);
411 
412     DocumentName name =
413         DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
414 
415     client.deleteDocument(name);
416 
417     List<String> actualRequests = mockService.getRequestPaths();
418     Assert.assertEquals(1, actualRequests.size());
419 
420     String apiClientHeaderKey =
421         mockService
422             .getRequestHeaders()
423             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
424             .iterator()
425             .next();
426     Assert.assertTrue(
427         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
428             .matcher(apiClientHeaderKey)
429             .matches());
430   }
431 
432   @Test
deleteDocumentExceptionTest()433   public void deleteDocumentExceptionTest() throws Exception {
434     ApiException exception =
435         ApiExceptionFactory.createException(
436             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
437     mockService.addException(exception);
438 
439     try {
440       DocumentName name =
441           DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
442       client.deleteDocument(name);
443       Assert.fail("No exception raised");
444     } catch (InvalidArgumentException e) {
445       // Expected exception.
446     }
447   }
448 
449   @Test
deleteDocumentTest2()450   public void deleteDocumentTest2() throws Exception {
451     Empty expectedResponse = Empty.newBuilder().build();
452     mockService.addResponse(expectedResponse);
453 
454     String name = "projects/project-5698/locations/location-5698/documents/document-5698";
455 
456     client.deleteDocument(name);
457 
458     List<String> actualRequests = mockService.getRequestPaths();
459     Assert.assertEquals(1, actualRequests.size());
460 
461     String apiClientHeaderKey =
462         mockService
463             .getRequestHeaders()
464             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
465             .iterator()
466             .next();
467     Assert.assertTrue(
468         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
469             .matcher(apiClientHeaderKey)
470             .matches());
471   }
472 
473   @Test
deleteDocumentExceptionTest2()474   public void deleteDocumentExceptionTest2() throws Exception {
475     ApiException exception =
476         ApiExceptionFactory.createException(
477             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
478     mockService.addException(exception);
479 
480     try {
481       String name = "projects/project-5698/locations/location-5698/documents/document-5698";
482       client.deleteDocument(name);
483       Assert.fail("No exception raised");
484     } catch (InvalidArgumentException e) {
485       // Expected exception.
486     }
487   }
488 
489   @Test
searchDocumentsTest()490   public void searchDocumentsTest() throws Exception {
491     SearchDocumentsResponse.MatchingDocument responsesElement =
492         SearchDocumentsResponse.MatchingDocument.newBuilder().build();
493     SearchDocumentsResponse expectedResponse =
494         SearchDocumentsResponse.newBuilder()
495             .setNextPageToken("")
496             .addAllMatchingDocuments(Arrays.asList(responsesElement))
497             .build();
498     mockService.addResponse(expectedResponse);
499 
500     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
501 
502     SearchDocumentsPagedResponse pagedListResponse = client.searchDocuments(parent);
503 
504     List<SearchDocumentsResponse.MatchingDocument> resources =
505         Lists.newArrayList(pagedListResponse.iterateAll());
506 
507     Assert.assertEquals(1, resources.size());
508     Assert.assertEquals(expectedResponse.getMatchingDocumentsList().get(0), resources.get(0));
509 
510     List<String> actualRequests = mockService.getRequestPaths();
511     Assert.assertEquals(1, actualRequests.size());
512 
513     String apiClientHeaderKey =
514         mockService
515             .getRequestHeaders()
516             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
517             .iterator()
518             .next();
519     Assert.assertTrue(
520         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
521             .matcher(apiClientHeaderKey)
522             .matches());
523   }
524 
525   @Test
searchDocumentsExceptionTest()526   public void searchDocumentsExceptionTest() throws Exception {
527     ApiException exception =
528         ApiExceptionFactory.createException(
529             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
530     mockService.addException(exception);
531 
532     try {
533       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
534       client.searchDocuments(parent);
535       Assert.fail("No exception raised");
536     } catch (InvalidArgumentException e) {
537       // Expected exception.
538     }
539   }
540 
541   @Test
searchDocumentsTest2()542   public void searchDocumentsTest2() throws Exception {
543     SearchDocumentsResponse.MatchingDocument responsesElement =
544         SearchDocumentsResponse.MatchingDocument.newBuilder().build();
545     SearchDocumentsResponse expectedResponse =
546         SearchDocumentsResponse.newBuilder()
547             .setNextPageToken("")
548             .addAllMatchingDocuments(Arrays.asList(responsesElement))
549             .build();
550     mockService.addResponse(expectedResponse);
551 
552     String parent = "projects/project-5833/locations/location-5833";
553 
554     SearchDocumentsPagedResponse pagedListResponse = client.searchDocuments(parent);
555 
556     List<SearchDocumentsResponse.MatchingDocument> resources =
557         Lists.newArrayList(pagedListResponse.iterateAll());
558 
559     Assert.assertEquals(1, resources.size());
560     Assert.assertEquals(expectedResponse.getMatchingDocumentsList().get(0), resources.get(0));
561 
562     List<String> actualRequests = mockService.getRequestPaths();
563     Assert.assertEquals(1, actualRequests.size());
564 
565     String apiClientHeaderKey =
566         mockService
567             .getRequestHeaders()
568             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
569             .iterator()
570             .next();
571     Assert.assertTrue(
572         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
573             .matcher(apiClientHeaderKey)
574             .matches());
575   }
576 
577   @Test
searchDocumentsExceptionTest2()578   public void searchDocumentsExceptionTest2() throws Exception {
579     ApiException exception =
580         ApiExceptionFactory.createException(
581             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
582     mockService.addException(exception);
583 
584     try {
585       String parent = "projects/project-5833/locations/location-5833";
586       client.searchDocuments(parent);
587       Assert.fail("No exception raised");
588     } catch (InvalidArgumentException e) {
589       // Expected exception.
590     }
591   }
592 
593   @Test
lockDocumentTest()594   public void lockDocumentTest() throws Exception {
595     Document expectedResponse =
596         Document.newBuilder()
597             .setName(
598                 DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]")
599                     .toString())
600             .setReferenceId("referenceId-16211514")
601             .setDisplayName("displayName1714148973")
602             .setTitle("title110371416")
603             .setDisplayUri("displayUri-914528950")
604             .setDocumentSchemaName(
605                 DocumentSchemaName.of("[PROJECT]", "[LOCATION]", "[DOCUMENT_SCHEMA]").toString())
606             .setStructuredContentUri("structuredContentUri-1039251868")
607             .addAllProperties(new ArrayList<Property>())
608             .setUpdateTime(Timestamp.newBuilder().build())
609             .setCreateTime(Timestamp.newBuilder().build())
610             .setRawDocumentFileType(RawDocumentFileType.forNumber(0))
611             .setAsyncEnabled(true)
612             .setContentCategory(ContentCategory.forNumber(0))
613             .setTextExtractionDisabled(true)
614             .setTextExtractionEnabled(true)
615             .setCreator("creator1028554796")
616             .setUpdater("updater-234430263")
617             .build();
618     mockService.addResponse(expectedResponse);
619 
620     DocumentName name =
621         DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
622 
623     Document actualResponse = client.lockDocument(name);
624     Assert.assertEquals(expectedResponse, actualResponse);
625 
626     List<String> actualRequests = mockService.getRequestPaths();
627     Assert.assertEquals(1, actualRequests.size());
628 
629     String apiClientHeaderKey =
630         mockService
631             .getRequestHeaders()
632             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
633             .iterator()
634             .next();
635     Assert.assertTrue(
636         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
637             .matcher(apiClientHeaderKey)
638             .matches());
639   }
640 
641   @Test
lockDocumentExceptionTest()642   public void lockDocumentExceptionTest() throws Exception {
643     ApiException exception =
644         ApiExceptionFactory.createException(
645             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
646     mockService.addException(exception);
647 
648     try {
649       DocumentName name =
650           DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]");
651       client.lockDocument(name);
652       Assert.fail("No exception raised");
653     } catch (InvalidArgumentException e) {
654       // Expected exception.
655     }
656   }
657 
658   @Test
lockDocumentTest2()659   public void lockDocumentTest2() throws Exception {
660     Document expectedResponse =
661         Document.newBuilder()
662             .setName(
663                 DocumentName.ofProjectLocationDocumentName("[PROJECT]", "[LOCATION]", "[DOCUMENT]")
664                     .toString())
665             .setReferenceId("referenceId-16211514")
666             .setDisplayName("displayName1714148973")
667             .setTitle("title110371416")
668             .setDisplayUri("displayUri-914528950")
669             .setDocumentSchemaName(
670                 DocumentSchemaName.of("[PROJECT]", "[LOCATION]", "[DOCUMENT_SCHEMA]").toString())
671             .setStructuredContentUri("structuredContentUri-1039251868")
672             .addAllProperties(new ArrayList<Property>())
673             .setUpdateTime(Timestamp.newBuilder().build())
674             .setCreateTime(Timestamp.newBuilder().build())
675             .setRawDocumentFileType(RawDocumentFileType.forNumber(0))
676             .setAsyncEnabled(true)
677             .setContentCategory(ContentCategory.forNumber(0))
678             .setTextExtractionDisabled(true)
679             .setTextExtractionEnabled(true)
680             .setCreator("creator1028554796")
681             .setUpdater("updater-234430263")
682             .build();
683     mockService.addResponse(expectedResponse);
684 
685     String name = "projects/project-5698/locations/location-5698/documents/document-5698";
686 
687     Document actualResponse = client.lockDocument(name);
688     Assert.assertEquals(expectedResponse, actualResponse);
689 
690     List<String> actualRequests = mockService.getRequestPaths();
691     Assert.assertEquals(1, actualRequests.size());
692 
693     String apiClientHeaderKey =
694         mockService
695             .getRequestHeaders()
696             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
697             .iterator()
698             .next();
699     Assert.assertTrue(
700         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
701             .matcher(apiClientHeaderKey)
702             .matches());
703   }
704 
705   @Test
lockDocumentExceptionTest2()706   public void lockDocumentExceptionTest2() throws Exception {
707     ApiException exception =
708         ApiExceptionFactory.createException(
709             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
710     mockService.addException(exception);
711 
712     try {
713       String name = "projects/project-5698/locations/location-5698/documents/document-5698";
714       client.lockDocument(name);
715       Assert.fail("No exception raised");
716     } catch (InvalidArgumentException e) {
717       // Expected exception.
718     }
719   }
720 
721   @Test
fetchAclTest()722   public void fetchAclTest() throws Exception {
723     FetchAclResponse expectedResponse =
724         FetchAclResponse.newBuilder()
725             .setPolicy(Policy.newBuilder().build())
726             .setMetadata(ResponseMetadata.newBuilder().build())
727             .build();
728     mockService.addResponse(expectedResponse);
729 
730     String resource = "projects/project-5313/locations/location-5313/documents/document-5313";
731 
732     FetchAclResponse actualResponse = client.fetchAcl(resource);
733     Assert.assertEquals(expectedResponse, actualResponse);
734 
735     List<String> actualRequests = mockService.getRequestPaths();
736     Assert.assertEquals(1, actualRequests.size());
737 
738     String apiClientHeaderKey =
739         mockService
740             .getRequestHeaders()
741             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
742             .iterator()
743             .next();
744     Assert.assertTrue(
745         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
746             .matcher(apiClientHeaderKey)
747             .matches());
748   }
749 
750   @Test
fetchAclExceptionTest()751   public void fetchAclExceptionTest() throws Exception {
752     ApiException exception =
753         ApiExceptionFactory.createException(
754             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
755     mockService.addException(exception);
756 
757     try {
758       String resource = "projects/project-5313/locations/location-5313/documents/document-5313";
759       client.fetchAcl(resource);
760       Assert.fail("No exception raised");
761     } catch (InvalidArgumentException e) {
762       // Expected exception.
763     }
764   }
765 
766   @Test
setAclTest()767   public void setAclTest() throws Exception {
768     SetAclResponse expectedResponse =
769         SetAclResponse.newBuilder()
770             .setPolicy(Policy.newBuilder().build())
771             .setMetadata(ResponseMetadata.newBuilder().build())
772             .build();
773     mockService.addResponse(expectedResponse);
774 
775     String resource = "projects/project-5313/locations/location-5313/documents/document-5313";
776     Policy policy = Policy.newBuilder().build();
777 
778     SetAclResponse actualResponse = client.setAcl(resource, policy);
779     Assert.assertEquals(expectedResponse, actualResponse);
780 
781     List<String> actualRequests = mockService.getRequestPaths();
782     Assert.assertEquals(1, actualRequests.size());
783 
784     String apiClientHeaderKey =
785         mockService
786             .getRequestHeaders()
787             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
788             .iterator()
789             .next();
790     Assert.assertTrue(
791         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
792             .matcher(apiClientHeaderKey)
793             .matches());
794   }
795 
796   @Test
setAclExceptionTest()797   public void setAclExceptionTest() throws Exception {
798     ApiException exception =
799         ApiExceptionFactory.createException(
800             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
801     mockService.addException(exception);
802 
803     try {
804       String resource = "projects/project-5313/locations/location-5313/documents/document-5313";
805       Policy policy = Policy.newBuilder().build();
806       client.setAcl(resource, policy);
807       Assert.fail("No exception raised");
808     } catch (InvalidArgumentException e) {
809       // Expected exception.
810     }
811   }
812 }
813