• 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.eventarc.v1;
18 
19 import static com.google.cloud.eventarc.v1.EventarcClient.ListChannelConnectionsPagedResponse;
20 import static com.google.cloud.eventarc.v1.EventarcClient.ListChannelsPagedResponse;
21 import static com.google.cloud.eventarc.v1.EventarcClient.ListLocationsPagedResponse;
22 import static com.google.cloud.eventarc.v1.EventarcClient.ListProvidersPagedResponse;
23 import static com.google.cloud.eventarc.v1.EventarcClient.ListTriggersPagedResponse;
24 
25 import com.google.api.gax.core.NoCredentialsProvider;
26 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
27 import com.google.api.gax.httpjson.testing.MockHttpService;
28 import com.google.api.gax.rpc.ApiClientHeaderProvider;
29 import com.google.api.gax.rpc.ApiException;
30 import com.google.api.gax.rpc.ApiExceptionFactory;
31 import com.google.api.gax.rpc.InvalidArgumentException;
32 import com.google.api.gax.rpc.StatusCode;
33 import com.google.api.gax.rpc.testing.FakeStatusCode;
34 import com.google.cloud.eventarc.v1.stub.HttpJsonEventarcStub;
35 import com.google.cloud.location.GetLocationRequest;
36 import com.google.cloud.location.ListLocationsRequest;
37 import com.google.cloud.location.ListLocationsResponse;
38 import com.google.cloud.location.Location;
39 import com.google.common.collect.Lists;
40 import com.google.iam.v1.AuditConfig;
41 import com.google.iam.v1.Binding;
42 import com.google.iam.v1.GetIamPolicyRequest;
43 import com.google.iam.v1.GetPolicyOptions;
44 import com.google.iam.v1.Policy;
45 import com.google.iam.v1.SetIamPolicyRequest;
46 import com.google.iam.v1.TestIamPermissionsRequest;
47 import com.google.iam.v1.TestIamPermissionsResponse;
48 import com.google.longrunning.Operation;
49 import com.google.protobuf.Any;
50 import com.google.protobuf.ByteString;
51 import com.google.protobuf.FieldMask;
52 import com.google.protobuf.Timestamp;
53 import java.io.IOException;
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.HashMap;
57 import java.util.List;
58 import java.util.concurrent.ExecutionException;
59 import javax.annotation.Generated;
60 import org.junit.After;
61 import org.junit.AfterClass;
62 import org.junit.Assert;
63 import org.junit.Before;
64 import org.junit.BeforeClass;
65 import org.junit.Test;
66 
67 @Generated("by gapic-generator-java")
68 public class EventarcClientHttpJsonTest {
69   private static MockHttpService mockService;
70   private static EventarcClient client;
71 
72   @BeforeClass
startStaticServer()73   public static void startStaticServer() throws IOException {
74     mockService =
75         new MockHttpService(
76             HttpJsonEventarcStub.getMethodDescriptors(), EventarcSettings.getDefaultEndpoint());
77     EventarcSettings settings =
78         EventarcSettings.newHttpJsonBuilder()
79             .setTransportChannelProvider(
80                 EventarcSettings.defaultHttpJsonTransportProviderBuilder()
81                     .setHttpTransport(mockService)
82                     .build())
83             .setCredentialsProvider(NoCredentialsProvider.create())
84             .build();
85     client = EventarcClient.create(settings);
86   }
87 
88   @AfterClass
stopServer()89   public static void stopServer() {
90     client.close();
91   }
92 
93   @Before
setUp()94   public void setUp() {}
95 
96   @After
tearDown()97   public void tearDown() throws Exception {
98     mockService.reset();
99   }
100 
101   @Test
getTriggerTest()102   public void getTriggerTest() throws Exception {
103     Trigger expectedResponse =
104         Trigger.newBuilder()
105             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
106             .setUid("uid115792")
107             .setCreateTime(Timestamp.newBuilder().build())
108             .setUpdateTime(Timestamp.newBuilder().build())
109             .addAllEventFilters(new ArrayList<EventFilter>())
110             .setServiceAccount("serviceAccount1079137720")
111             .setDestination(Destination.newBuilder().build())
112             .setTransport(Transport.newBuilder().build())
113             .putAllLabels(new HashMap<String, String>())
114             .setChannel("channel738950403")
115             .putAllConditions(new HashMap<String, StateCondition>())
116             .setEtag("etag3123477")
117             .build();
118     mockService.addResponse(expectedResponse);
119 
120     TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]");
121 
122     Trigger actualResponse = client.getTrigger(name);
123     Assert.assertEquals(expectedResponse, actualResponse);
124 
125     List<String> actualRequests = mockService.getRequestPaths();
126     Assert.assertEquals(1, actualRequests.size());
127 
128     String apiClientHeaderKey =
129         mockService
130             .getRequestHeaders()
131             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
132             .iterator()
133             .next();
134     Assert.assertTrue(
135         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
136             .matcher(apiClientHeaderKey)
137             .matches());
138   }
139 
140   @Test
getTriggerExceptionTest()141   public void getTriggerExceptionTest() throws Exception {
142     ApiException exception =
143         ApiExceptionFactory.createException(
144             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
145     mockService.addException(exception);
146 
147     try {
148       TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]");
149       client.getTrigger(name);
150       Assert.fail("No exception raised");
151     } catch (InvalidArgumentException e) {
152       // Expected exception.
153     }
154   }
155 
156   @Test
getTriggerTest2()157   public void getTriggerTest2() throws Exception {
158     Trigger expectedResponse =
159         Trigger.newBuilder()
160             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
161             .setUid("uid115792")
162             .setCreateTime(Timestamp.newBuilder().build())
163             .setUpdateTime(Timestamp.newBuilder().build())
164             .addAllEventFilters(new ArrayList<EventFilter>())
165             .setServiceAccount("serviceAccount1079137720")
166             .setDestination(Destination.newBuilder().build())
167             .setTransport(Transport.newBuilder().build())
168             .putAllLabels(new HashMap<String, String>())
169             .setChannel("channel738950403")
170             .putAllConditions(new HashMap<String, StateCondition>())
171             .setEtag("etag3123477")
172             .build();
173     mockService.addResponse(expectedResponse);
174 
175     String name = "projects/project-3275/locations/location-3275/triggers/trigger-3275";
176 
177     Trigger actualResponse = client.getTrigger(name);
178     Assert.assertEquals(expectedResponse, actualResponse);
179 
180     List<String> actualRequests = mockService.getRequestPaths();
181     Assert.assertEquals(1, actualRequests.size());
182 
183     String apiClientHeaderKey =
184         mockService
185             .getRequestHeaders()
186             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
187             .iterator()
188             .next();
189     Assert.assertTrue(
190         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
191             .matcher(apiClientHeaderKey)
192             .matches());
193   }
194 
195   @Test
getTriggerExceptionTest2()196   public void getTriggerExceptionTest2() throws Exception {
197     ApiException exception =
198         ApiExceptionFactory.createException(
199             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
200     mockService.addException(exception);
201 
202     try {
203       String name = "projects/project-3275/locations/location-3275/triggers/trigger-3275";
204       client.getTrigger(name);
205       Assert.fail("No exception raised");
206     } catch (InvalidArgumentException e) {
207       // Expected exception.
208     }
209   }
210 
211   @Test
listTriggersTest()212   public void listTriggersTest() throws Exception {
213     Trigger responsesElement = Trigger.newBuilder().build();
214     ListTriggersResponse expectedResponse =
215         ListTriggersResponse.newBuilder()
216             .setNextPageToken("")
217             .addAllTriggers(Arrays.asList(responsesElement))
218             .build();
219     mockService.addResponse(expectedResponse);
220 
221     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
222 
223     ListTriggersPagedResponse pagedListResponse = client.listTriggers(parent);
224 
225     List<Trigger> resources = Lists.newArrayList(pagedListResponse.iterateAll());
226 
227     Assert.assertEquals(1, resources.size());
228     Assert.assertEquals(expectedResponse.getTriggersList().get(0), resources.get(0));
229 
230     List<String> actualRequests = mockService.getRequestPaths();
231     Assert.assertEquals(1, actualRequests.size());
232 
233     String apiClientHeaderKey =
234         mockService
235             .getRequestHeaders()
236             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
237             .iterator()
238             .next();
239     Assert.assertTrue(
240         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
241             .matcher(apiClientHeaderKey)
242             .matches());
243   }
244 
245   @Test
listTriggersExceptionTest()246   public void listTriggersExceptionTest() throws Exception {
247     ApiException exception =
248         ApiExceptionFactory.createException(
249             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
250     mockService.addException(exception);
251 
252     try {
253       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
254       client.listTriggers(parent);
255       Assert.fail("No exception raised");
256     } catch (InvalidArgumentException e) {
257       // Expected exception.
258     }
259   }
260 
261   @Test
listTriggersTest2()262   public void listTriggersTest2() throws Exception {
263     Trigger responsesElement = Trigger.newBuilder().build();
264     ListTriggersResponse expectedResponse =
265         ListTriggersResponse.newBuilder()
266             .setNextPageToken("")
267             .addAllTriggers(Arrays.asList(responsesElement))
268             .build();
269     mockService.addResponse(expectedResponse);
270 
271     String parent = "projects/project-5833/locations/location-5833";
272 
273     ListTriggersPagedResponse pagedListResponse = client.listTriggers(parent);
274 
275     List<Trigger> resources = Lists.newArrayList(pagedListResponse.iterateAll());
276 
277     Assert.assertEquals(1, resources.size());
278     Assert.assertEquals(expectedResponse.getTriggersList().get(0), resources.get(0));
279 
280     List<String> actualRequests = mockService.getRequestPaths();
281     Assert.assertEquals(1, actualRequests.size());
282 
283     String apiClientHeaderKey =
284         mockService
285             .getRequestHeaders()
286             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
287             .iterator()
288             .next();
289     Assert.assertTrue(
290         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
291             .matcher(apiClientHeaderKey)
292             .matches());
293   }
294 
295   @Test
listTriggersExceptionTest2()296   public void listTriggersExceptionTest2() throws Exception {
297     ApiException exception =
298         ApiExceptionFactory.createException(
299             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
300     mockService.addException(exception);
301 
302     try {
303       String parent = "projects/project-5833/locations/location-5833";
304       client.listTriggers(parent);
305       Assert.fail("No exception raised");
306     } catch (InvalidArgumentException e) {
307       // Expected exception.
308     }
309   }
310 
311   @Test
createTriggerTest()312   public void createTriggerTest() throws Exception {
313     Trigger expectedResponse =
314         Trigger.newBuilder()
315             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
316             .setUid("uid115792")
317             .setCreateTime(Timestamp.newBuilder().build())
318             .setUpdateTime(Timestamp.newBuilder().build())
319             .addAllEventFilters(new ArrayList<EventFilter>())
320             .setServiceAccount("serviceAccount1079137720")
321             .setDestination(Destination.newBuilder().build())
322             .setTransport(Transport.newBuilder().build())
323             .putAllLabels(new HashMap<String, String>())
324             .setChannel("channel738950403")
325             .putAllConditions(new HashMap<String, StateCondition>())
326             .setEtag("etag3123477")
327             .build();
328     Operation resultOperation =
329         Operation.newBuilder()
330             .setName("createTriggerTest")
331             .setDone(true)
332             .setResponse(Any.pack(expectedResponse))
333             .build();
334     mockService.addResponse(resultOperation);
335 
336     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
337     Trigger trigger = Trigger.newBuilder().build();
338     String triggerId = "triggerId-648752909";
339 
340     Trigger actualResponse = client.createTriggerAsync(parent, trigger, triggerId).get();
341     Assert.assertEquals(expectedResponse, actualResponse);
342 
343     List<String> actualRequests = mockService.getRequestPaths();
344     Assert.assertEquals(1, actualRequests.size());
345 
346     String apiClientHeaderKey =
347         mockService
348             .getRequestHeaders()
349             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
350             .iterator()
351             .next();
352     Assert.assertTrue(
353         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
354             .matcher(apiClientHeaderKey)
355             .matches());
356   }
357 
358   @Test
createTriggerExceptionTest()359   public void createTriggerExceptionTest() throws Exception {
360     ApiException exception =
361         ApiExceptionFactory.createException(
362             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
363     mockService.addException(exception);
364 
365     try {
366       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
367       Trigger trigger = Trigger.newBuilder().build();
368       String triggerId = "triggerId-648752909";
369       client.createTriggerAsync(parent, trigger, triggerId).get();
370       Assert.fail("No exception raised");
371     } catch (ExecutionException e) {
372     }
373   }
374 
375   @Test
createTriggerTest2()376   public void createTriggerTest2() throws Exception {
377     Trigger expectedResponse =
378         Trigger.newBuilder()
379             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
380             .setUid("uid115792")
381             .setCreateTime(Timestamp.newBuilder().build())
382             .setUpdateTime(Timestamp.newBuilder().build())
383             .addAllEventFilters(new ArrayList<EventFilter>())
384             .setServiceAccount("serviceAccount1079137720")
385             .setDestination(Destination.newBuilder().build())
386             .setTransport(Transport.newBuilder().build())
387             .putAllLabels(new HashMap<String, String>())
388             .setChannel("channel738950403")
389             .putAllConditions(new HashMap<String, StateCondition>())
390             .setEtag("etag3123477")
391             .build();
392     Operation resultOperation =
393         Operation.newBuilder()
394             .setName("createTriggerTest")
395             .setDone(true)
396             .setResponse(Any.pack(expectedResponse))
397             .build();
398     mockService.addResponse(resultOperation);
399 
400     String parent = "projects/project-5833/locations/location-5833";
401     Trigger trigger = Trigger.newBuilder().build();
402     String triggerId = "triggerId-648752909";
403 
404     Trigger actualResponse = client.createTriggerAsync(parent, trigger, triggerId).get();
405     Assert.assertEquals(expectedResponse, actualResponse);
406 
407     List<String> actualRequests = mockService.getRequestPaths();
408     Assert.assertEquals(1, actualRequests.size());
409 
410     String apiClientHeaderKey =
411         mockService
412             .getRequestHeaders()
413             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
414             .iterator()
415             .next();
416     Assert.assertTrue(
417         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
418             .matcher(apiClientHeaderKey)
419             .matches());
420   }
421 
422   @Test
createTriggerExceptionTest2()423   public void createTriggerExceptionTest2() throws Exception {
424     ApiException exception =
425         ApiExceptionFactory.createException(
426             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
427     mockService.addException(exception);
428 
429     try {
430       String parent = "projects/project-5833/locations/location-5833";
431       Trigger trigger = Trigger.newBuilder().build();
432       String triggerId = "triggerId-648752909";
433       client.createTriggerAsync(parent, trigger, triggerId).get();
434       Assert.fail("No exception raised");
435     } catch (ExecutionException e) {
436     }
437   }
438 
439   @Test
updateTriggerTest()440   public void updateTriggerTest() throws Exception {
441     Trigger expectedResponse =
442         Trigger.newBuilder()
443             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
444             .setUid("uid115792")
445             .setCreateTime(Timestamp.newBuilder().build())
446             .setUpdateTime(Timestamp.newBuilder().build())
447             .addAllEventFilters(new ArrayList<EventFilter>())
448             .setServiceAccount("serviceAccount1079137720")
449             .setDestination(Destination.newBuilder().build())
450             .setTransport(Transport.newBuilder().build())
451             .putAllLabels(new HashMap<String, String>())
452             .setChannel("channel738950403")
453             .putAllConditions(new HashMap<String, StateCondition>())
454             .setEtag("etag3123477")
455             .build();
456     Operation resultOperation =
457         Operation.newBuilder()
458             .setName("updateTriggerTest")
459             .setDone(true)
460             .setResponse(Any.pack(expectedResponse))
461             .build();
462     mockService.addResponse(resultOperation);
463 
464     Trigger trigger =
465         Trigger.newBuilder()
466             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
467             .setUid("uid115792")
468             .setCreateTime(Timestamp.newBuilder().build())
469             .setUpdateTime(Timestamp.newBuilder().build())
470             .addAllEventFilters(new ArrayList<EventFilter>())
471             .setServiceAccount("serviceAccount1079137720")
472             .setDestination(Destination.newBuilder().build())
473             .setTransport(Transport.newBuilder().build())
474             .putAllLabels(new HashMap<String, String>())
475             .setChannel("channel738950403")
476             .putAllConditions(new HashMap<String, StateCondition>())
477             .setEtag("etag3123477")
478             .build();
479     FieldMask updateMask = FieldMask.newBuilder().build();
480     boolean allowMissing = true;
481 
482     Trigger actualResponse = client.updateTriggerAsync(trigger, updateMask, allowMissing).get();
483     Assert.assertEquals(expectedResponse, actualResponse);
484 
485     List<String> actualRequests = mockService.getRequestPaths();
486     Assert.assertEquals(1, actualRequests.size());
487 
488     String apiClientHeaderKey =
489         mockService
490             .getRequestHeaders()
491             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
492             .iterator()
493             .next();
494     Assert.assertTrue(
495         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
496             .matcher(apiClientHeaderKey)
497             .matches());
498   }
499 
500   @Test
updateTriggerExceptionTest()501   public void updateTriggerExceptionTest() throws Exception {
502     ApiException exception =
503         ApiExceptionFactory.createException(
504             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
505     mockService.addException(exception);
506 
507     try {
508       Trigger trigger =
509           Trigger.newBuilder()
510               .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
511               .setUid("uid115792")
512               .setCreateTime(Timestamp.newBuilder().build())
513               .setUpdateTime(Timestamp.newBuilder().build())
514               .addAllEventFilters(new ArrayList<EventFilter>())
515               .setServiceAccount("serviceAccount1079137720")
516               .setDestination(Destination.newBuilder().build())
517               .setTransport(Transport.newBuilder().build())
518               .putAllLabels(new HashMap<String, String>())
519               .setChannel("channel738950403")
520               .putAllConditions(new HashMap<String, StateCondition>())
521               .setEtag("etag3123477")
522               .build();
523       FieldMask updateMask = FieldMask.newBuilder().build();
524       boolean allowMissing = true;
525       client.updateTriggerAsync(trigger, updateMask, allowMissing).get();
526       Assert.fail("No exception raised");
527     } catch (ExecutionException e) {
528     }
529   }
530 
531   @Test
deleteTriggerTest()532   public void deleteTriggerTest() throws Exception {
533     Trigger expectedResponse =
534         Trigger.newBuilder()
535             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
536             .setUid("uid115792")
537             .setCreateTime(Timestamp.newBuilder().build())
538             .setUpdateTime(Timestamp.newBuilder().build())
539             .addAllEventFilters(new ArrayList<EventFilter>())
540             .setServiceAccount("serviceAccount1079137720")
541             .setDestination(Destination.newBuilder().build())
542             .setTransport(Transport.newBuilder().build())
543             .putAllLabels(new HashMap<String, String>())
544             .setChannel("channel738950403")
545             .putAllConditions(new HashMap<String, StateCondition>())
546             .setEtag("etag3123477")
547             .build();
548     Operation resultOperation =
549         Operation.newBuilder()
550             .setName("deleteTriggerTest")
551             .setDone(true)
552             .setResponse(Any.pack(expectedResponse))
553             .build();
554     mockService.addResponse(resultOperation);
555 
556     TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]");
557     boolean allowMissing = true;
558 
559     Trigger actualResponse = client.deleteTriggerAsync(name, allowMissing).get();
560     Assert.assertEquals(expectedResponse, actualResponse);
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
deleteTriggerExceptionTest()578   public void deleteTriggerExceptionTest() 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       TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]");
586       boolean allowMissing = true;
587       client.deleteTriggerAsync(name, allowMissing).get();
588       Assert.fail("No exception raised");
589     } catch (ExecutionException e) {
590     }
591   }
592 
593   @Test
deleteTriggerTest2()594   public void deleteTriggerTest2() throws Exception {
595     Trigger expectedResponse =
596         Trigger.newBuilder()
597             .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString())
598             .setUid("uid115792")
599             .setCreateTime(Timestamp.newBuilder().build())
600             .setUpdateTime(Timestamp.newBuilder().build())
601             .addAllEventFilters(new ArrayList<EventFilter>())
602             .setServiceAccount("serviceAccount1079137720")
603             .setDestination(Destination.newBuilder().build())
604             .setTransport(Transport.newBuilder().build())
605             .putAllLabels(new HashMap<String, String>())
606             .setChannel("channel738950403")
607             .putAllConditions(new HashMap<String, StateCondition>())
608             .setEtag("etag3123477")
609             .build();
610     Operation resultOperation =
611         Operation.newBuilder()
612             .setName("deleteTriggerTest")
613             .setDone(true)
614             .setResponse(Any.pack(expectedResponse))
615             .build();
616     mockService.addResponse(resultOperation);
617 
618     String name = "projects/project-3275/locations/location-3275/triggers/trigger-3275";
619     boolean allowMissing = true;
620 
621     Trigger actualResponse = client.deleteTriggerAsync(name, allowMissing).get();
622     Assert.assertEquals(expectedResponse, actualResponse);
623 
624     List<String> actualRequests = mockService.getRequestPaths();
625     Assert.assertEquals(1, actualRequests.size());
626 
627     String apiClientHeaderKey =
628         mockService
629             .getRequestHeaders()
630             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
631             .iterator()
632             .next();
633     Assert.assertTrue(
634         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
635             .matcher(apiClientHeaderKey)
636             .matches());
637   }
638 
639   @Test
deleteTriggerExceptionTest2()640   public void deleteTriggerExceptionTest2() throws Exception {
641     ApiException exception =
642         ApiExceptionFactory.createException(
643             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
644     mockService.addException(exception);
645 
646     try {
647       String name = "projects/project-3275/locations/location-3275/triggers/trigger-3275";
648       boolean allowMissing = true;
649       client.deleteTriggerAsync(name, allowMissing).get();
650       Assert.fail("No exception raised");
651     } catch (ExecutionException e) {
652     }
653   }
654 
655   @Test
getChannelTest()656   public void getChannelTest() throws Exception {
657     Channel expectedResponse =
658         Channel.newBuilder()
659             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
660             .setUid("uid115792")
661             .setCreateTime(Timestamp.newBuilder().build())
662             .setUpdateTime(Timestamp.newBuilder().build())
663             .setProvider("provider-987494927")
664             .setActivationToken("activationToken1276937859")
665             .setCryptoKeyName("cryptoKeyName1447084425")
666             .build();
667     mockService.addResponse(expectedResponse);
668 
669     ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]");
670 
671     Channel actualResponse = client.getChannel(name);
672     Assert.assertEquals(expectedResponse, actualResponse);
673 
674     List<String> actualRequests = mockService.getRequestPaths();
675     Assert.assertEquals(1, actualRequests.size());
676 
677     String apiClientHeaderKey =
678         mockService
679             .getRequestHeaders()
680             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
681             .iterator()
682             .next();
683     Assert.assertTrue(
684         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
685             .matcher(apiClientHeaderKey)
686             .matches());
687   }
688 
689   @Test
getChannelExceptionTest()690   public void getChannelExceptionTest() throws Exception {
691     ApiException exception =
692         ApiExceptionFactory.createException(
693             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
694     mockService.addException(exception);
695 
696     try {
697       ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]");
698       client.getChannel(name);
699       Assert.fail("No exception raised");
700     } catch (InvalidArgumentException e) {
701       // Expected exception.
702     }
703   }
704 
705   @Test
getChannelTest2()706   public void getChannelTest2() throws Exception {
707     Channel expectedResponse =
708         Channel.newBuilder()
709             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
710             .setUid("uid115792")
711             .setCreateTime(Timestamp.newBuilder().build())
712             .setUpdateTime(Timestamp.newBuilder().build())
713             .setProvider("provider-987494927")
714             .setActivationToken("activationToken1276937859")
715             .setCryptoKeyName("cryptoKeyName1447084425")
716             .build();
717     mockService.addResponse(expectedResponse);
718 
719     String name = "projects/project-3296/locations/location-3296/channels/channel-3296";
720 
721     Channel actualResponse = client.getChannel(name);
722     Assert.assertEquals(expectedResponse, actualResponse);
723 
724     List<String> actualRequests = mockService.getRequestPaths();
725     Assert.assertEquals(1, actualRequests.size());
726 
727     String apiClientHeaderKey =
728         mockService
729             .getRequestHeaders()
730             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
731             .iterator()
732             .next();
733     Assert.assertTrue(
734         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
735             .matcher(apiClientHeaderKey)
736             .matches());
737   }
738 
739   @Test
getChannelExceptionTest2()740   public void getChannelExceptionTest2() throws Exception {
741     ApiException exception =
742         ApiExceptionFactory.createException(
743             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
744     mockService.addException(exception);
745 
746     try {
747       String name = "projects/project-3296/locations/location-3296/channels/channel-3296";
748       client.getChannel(name);
749       Assert.fail("No exception raised");
750     } catch (InvalidArgumentException e) {
751       // Expected exception.
752     }
753   }
754 
755   @Test
listChannelsTest()756   public void listChannelsTest() throws Exception {
757     Channel responsesElement = Channel.newBuilder().build();
758     ListChannelsResponse expectedResponse =
759         ListChannelsResponse.newBuilder()
760             .setNextPageToken("")
761             .addAllChannels(Arrays.asList(responsesElement))
762             .build();
763     mockService.addResponse(expectedResponse);
764 
765     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
766 
767     ListChannelsPagedResponse pagedListResponse = client.listChannels(parent);
768 
769     List<Channel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
770 
771     Assert.assertEquals(1, resources.size());
772     Assert.assertEquals(expectedResponse.getChannelsList().get(0), resources.get(0));
773 
774     List<String> actualRequests = mockService.getRequestPaths();
775     Assert.assertEquals(1, actualRequests.size());
776 
777     String apiClientHeaderKey =
778         mockService
779             .getRequestHeaders()
780             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
781             .iterator()
782             .next();
783     Assert.assertTrue(
784         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
785             .matcher(apiClientHeaderKey)
786             .matches());
787   }
788 
789   @Test
listChannelsExceptionTest()790   public void listChannelsExceptionTest() throws Exception {
791     ApiException exception =
792         ApiExceptionFactory.createException(
793             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
794     mockService.addException(exception);
795 
796     try {
797       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
798       client.listChannels(parent);
799       Assert.fail("No exception raised");
800     } catch (InvalidArgumentException e) {
801       // Expected exception.
802     }
803   }
804 
805   @Test
listChannelsTest2()806   public void listChannelsTest2() throws Exception {
807     Channel responsesElement = Channel.newBuilder().build();
808     ListChannelsResponse expectedResponse =
809         ListChannelsResponse.newBuilder()
810             .setNextPageToken("")
811             .addAllChannels(Arrays.asList(responsesElement))
812             .build();
813     mockService.addResponse(expectedResponse);
814 
815     String parent = "projects/project-5833/locations/location-5833";
816 
817     ListChannelsPagedResponse pagedListResponse = client.listChannels(parent);
818 
819     List<Channel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
820 
821     Assert.assertEquals(1, resources.size());
822     Assert.assertEquals(expectedResponse.getChannelsList().get(0), resources.get(0));
823 
824     List<String> actualRequests = mockService.getRequestPaths();
825     Assert.assertEquals(1, actualRequests.size());
826 
827     String apiClientHeaderKey =
828         mockService
829             .getRequestHeaders()
830             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
831             .iterator()
832             .next();
833     Assert.assertTrue(
834         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
835             .matcher(apiClientHeaderKey)
836             .matches());
837   }
838 
839   @Test
listChannelsExceptionTest2()840   public void listChannelsExceptionTest2() throws Exception {
841     ApiException exception =
842         ApiExceptionFactory.createException(
843             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
844     mockService.addException(exception);
845 
846     try {
847       String parent = "projects/project-5833/locations/location-5833";
848       client.listChannels(parent);
849       Assert.fail("No exception raised");
850     } catch (InvalidArgumentException e) {
851       // Expected exception.
852     }
853   }
854 
855   @Test
createChannelTest()856   public void createChannelTest() throws Exception {
857     Channel expectedResponse =
858         Channel.newBuilder()
859             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
860             .setUid("uid115792")
861             .setCreateTime(Timestamp.newBuilder().build())
862             .setUpdateTime(Timestamp.newBuilder().build())
863             .setProvider("provider-987494927")
864             .setActivationToken("activationToken1276937859")
865             .setCryptoKeyName("cryptoKeyName1447084425")
866             .build();
867     Operation resultOperation =
868         Operation.newBuilder()
869             .setName("createChannelTest")
870             .setDone(true)
871             .setResponse(Any.pack(expectedResponse))
872             .build();
873     mockService.addResponse(resultOperation);
874 
875     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
876     Channel channel = Channel.newBuilder().build();
877     String channelId = "channelId1461735806";
878 
879     Channel actualResponse = client.createChannelAsync(parent, channel, channelId).get();
880     Assert.assertEquals(expectedResponse, actualResponse);
881 
882     List<String> actualRequests = mockService.getRequestPaths();
883     Assert.assertEquals(1, actualRequests.size());
884 
885     String apiClientHeaderKey =
886         mockService
887             .getRequestHeaders()
888             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
889             .iterator()
890             .next();
891     Assert.assertTrue(
892         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
893             .matcher(apiClientHeaderKey)
894             .matches());
895   }
896 
897   @Test
createChannelExceptionTest()898   public void createChannelExceptionTest() throws Exception {
899     ApiException exception =
900         ApiExceptionFactory.createException(
901             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
902     mockService.addException(exception);
903 
904     try {
905       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
906       Channel channel = Channel.newBuilder().build();
907       String channelId = "channelId1461735806";
908       client.createChannelAsync(parent, channel, channelId).get();
909       Assert.fail("No exception raised");
910     } catch (ExecutionException e) {
911     }
912   }
913 
914   @Test
createChannelTest2()915   public void createChannelTest2() throws Exception {
916     Channel expectedResponse =
917         Channel.newBuilder()
918             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
919             .setUid("uid115792")
920             .setCreateTime(Timestamp.newBuilder().build())
921             .setUpdateTime(Timestamp.newBuilder().build())
922             .setProvider("provider-987494927")
923             .setActivationToken("activationToken1276937859")
924             .setCryptoKeyName("cryptoKeyName1447084425")
925             .build();
926     Operation resultOperation =
927         Operation.newBuilder()
928             .setName("createChannelTest")
929             .setDone(true)
930             .setResponse(Any.pack(expectedResponse))
931             .build();
932     mockService.addResponse(resultOperation);
933 
934     String parent = "projects/project-5833/locations/location-5833";
935     Channel channel = Channel.newBuilder().build();
936     String channelId = "channelId1461735806";
937 
938     Channel actualResponse = client.createChannelAsync(parent, channel, channelId).get();
939     Assert.assertEquals(expectedResponse, actualResponse);
940 
941     List<String> actualRequests = mockService.getRequestPaths();
942     Assert.assertEquals(1, actualRequests.size());
943 
944     String apiClientHeaderKey =
945         mockService
946             .getRequestHeaders()
947             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
948             .iterator()
949             .next();
950     Assert.assertTrue(
951         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
952             .matcher(apiClientHeaderKey)
953             .matches());
954   }
955 
956   @Test
createChannelExceptionTest2()957   public void createChannelExceptionTest2() throws Exception {
958     ApiException exception =
959         ApiExceptionFactory.createException(
960             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
961     mockService.addException(exception);
962 
963     try {
964       String parent = "projects/project-5833/locations/location-5833";
965       Channel channel = Channel.newBuilder().build();
966       String channelId = "channelId1461735806";
967       client.createChannelAsync(parent, channel, channelId).get();
968       Assert.fail("No exception raised");
969     } catch (ExecutionException e) {
970     }
971   }
972 
973   @Test
updateChannelTest()974   public void updateChannelTest() throws Exception {
975     Channel expectedResponse =
976         Channel.newBuilder()
977             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
978             .setUid("uid115792")
979             .setCreateTime(Timestamp.newBuilder().build())
980             .setUpdateTime(Timestamp.newBuilder().build())
981             .setProvider("provider-987494927")
982             .setActivationToken("activationToken1276937859")
983             .setCryptoKeyName("cryptoKeyName1447084425")
984             .build();
985     Operation resultOperation =
986         Operation.newBuilder()
987             .setName("updateChannelTest")
988             .setDone(true)
989             .setResponse(Any.pack(expectedResponse))
990             .build();
991     mockService.addResponse(resultOperation);
992 
993     Channel channel =
994         Channel.newBuilder()
995             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
996             .setUid("uid115792")
997             .setCreateTime(Timestamp.newBuilder().build())
998             .setUpdateTime(Timestamp.newBuilder().build())
999             .setProvider("provider-987494927")
1000             .setActivationToken("activationToken1276937859")
1001             .setCryptoKeyName("cryptoKeyName1447084425")
1002             .build();
1003     FieldMask updateMask = FieldMask.newBuilder().build();
1004 
1005     Channel actualResponse = client.updateChannelAsync(channel, updateMask).get();
1006     Assert.assertEquals(expectedResponse, actualResponse);
1007 
1008     List<String> actualRequests = mockService.getRequestPaths();
1009     Assert.assertEquals(1, actualRequests.size());
1010 
1011     String apiClientHeaderKey =
1012         mockService
1013             .getRequestHeaders()
1014             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1015             .iterator()
1016             .next();
1017     Assert.assertTrue(
1018         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1019             .matcher(apiClientHeaderKey)
1020             .matches());
1021   }
1022 
1023   @Test
updateChannelExceptionTest()1024   public void updateChannelExceptionTest() throws Exception {
1025     ApiException exception =
1026         ApiExceptionFactory.createException(
1027             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1028     mockService.addException(exception);
1029 
1030     try {
1031       Channel channel =
1032           Channel.newBuilder()
1033               .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1034               .setUid("uid115792")
1035               .setCreateTime(Timestamp.newBuilder().build())
1036               .setUpdateTime(Timestamp.newBuilder().build())
1037               .setProvider("provider-987494927")
1038               .setActivationToken("activationToken1276937859")
1039               .setCryptoKeyName("cryptoKeyName1447084425")
1040               .build();
1041       FieldMask updateMask = FieldMask.newBuilder().build();
1042       client.updateChannelAsync(channel, updateMask).get();
1043       Assert.fail("No exception raised");
1044     } catch (ExecutionException e) {
1045     }
1046   }
1047 
1048   @Test
deleteChannelTest()1049   public void deleteChannelTest() throws Exception {
1050     Channel expectedResponse =
1051         Channel.newBuilder()
1052             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1053             .setUid("uid115792")
1054             .setCreateTime(Timestamp.newBuilder().build())
1055             .setUpdateTime(Timestamp.newBuilder().build())
1056             .setProvider("provider-987494927")
1057             .setActivationToken("activationToken1276937859")
1058             .setCryptoKeyName("cryptoKeyName1447084425")
1059             .build();
1060     Operation resultOperation =
1061         Operation.newBuilder()
1062             .setName("deleteChannelTest")
1063             .setDone(true)
1064             .setResponse(Any.pack(expectedResponse))
1065             .build();
1066     mockService.addResponse(resultOperation);
1067 
1068     ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]");
1069 
1070     Channel actualResponse = client.deleteChannelAsync(name).get();
1071     Assert.assertEquals(expectedResponse, actualResponse);
1072 
1073     List<String> actualRequests = mockService.getRequestPaths();
1074     Assert.assertEquals(1, actualRequests.size());
1075 
1076     String apiClientHeaderKey =
1077         mockService
1078             .getRequestHeaders()
1079             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1080             .iterator()
1081             .next();
1082     Assert.assertTrue(
1083         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1084             .matcher(apiClientHeaderKey)
1085             .matches());
1086   }
1087 
1088   @Test
deleteChannelExceptionTest()1089   public void deleteChannelExceptionTest() throws Exception {
1090     ApiException exception =
1091         ApiExceptionFactory.createException(
1092             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1093     mockService.addException(exception);
1094 
1095     try {
1096       ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]");
1097       client.deleteChannelAsync(name).get();
1098       Assert.fail("No exception raised");
1099     } catch (ExecutionException e) {
1100     }
1101   }
1102 
1103   @Test
deleteChannelTest2()1104   public void deleteChannelTest2() throws Exception {
1105     Channel expectedResponse =
1106         Channel.newBuilder()
1107             .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1108             .setUid("uid115792")
1109             .setCreateTime(Timestamp.newBuilder().build())
1110             .setUpdateTime(Timestamp.newBuilder().build())
1111             .setProvider("provider-987494927")
1112             .setActivationToken("activationToken1276937859")
1113             .setCryptoKeyName("cryptoKeyName1447084425")
1114             .build();
1115     Operation resultOperation =
1116         Operation.newBuilder()
1117             .setName("deleteChannelTest")
1118             .setDone(true)
1119             .setResponse(Any.pack(expectedResponse))
1120             .build();
1121     mockService.addResponse(resultOperation);
1122 
1123     String name = "projects/project-3296/locations/location-3296/channels/channel-3296";
1124 
1125     Channel actualResponse = client.deleteChannelAsync(name).get();
1126     Assert.assertEquals(expectedResponse, actualResponse);
1127 
1128     List<String> actualRequests = mockService.getRequestPaths();
1129     Assert.assertEquals(1, actualRequests.size());
1130 
1131     String apiClientHeaderKey =
1132         mockService
1133             .getRequestHeaders()
1134             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1135             .iterator()
1136             .next();
1137     Assert.assertTrue(
1138         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1139             .matcher(apiClientHeaderKey)
1140             .matches());
1141   }
1142 
1143   @Test
deleteChannelExceptionTest2()1144   public void deleteChannelExceptionTest2() throws Exception {
1145     ApiException exception =
1146         ApiExceptionFactory.createException(
1147             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1148     mockService.addException(exception);
1149 
1150     try {
1151       String name = "projects/project-3296/locations/location-3296/channels/channel-3296";
1152       client.deleteChannelAsync(name).get();
1153       Assert.fail("No exception raised");
1154     } catch (ExecutionException e) {
1155     }
1156   }
1157 
1158   @Test
getProviderTest()1159   public void getProviderTest() throws Exception {
1160     Provider expectedResponse =
1161         Provider.newBuilder()
1162             .setName(ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]").toString())
1163             .setDisplayName("displayName1714148973")
1164             .addAllEventTypes(new ArrayList<EventType>())
1165             .build();
1166     mockService.addResponse(expectedResponse);
1167 
1168     ProviderName name = ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]");
1169 
1170     Provider actualResponse = client.getProvider(name);
1171     Assert.assertEquals(expectedResponse, actualResponse);
1172 
1173     List<String> actualRequests = mockService.getRequestPaths();
1174     Assert.assertEquals(1, actualRequests.size());
1175 
1176     String apiClientHeaderKey =
1177         mockService
1178             .getRequestHeaders()
1179             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1180             .iterator()
1181             .next();
1182     Assert.assertTrue(
1183         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1184             .matcher(apiClientHeaderKey)
1185             .matches());
1186   }
1187 
1188   @Test
getProviderExceptionTest()1189   public void getProviderExceptionTest() throws Exception {
1190     ApiException exception =
1191         ApiExceptionFactory.createException(
1192             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1193     mockService.addException(exception);
1194 
1195     try {
1196       ProviderName name = ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]");
1197       client.getProvider(name);
1198       Assert.fail("No exception raised");
1199     } catch (InvalidArgumentException e) {
1200       // Expected exception.
1201     }
1202   }
1203 
1204   @Test
getProviderTest2()1205   public void getProviderTest2() throws Exception {
1206     Provider expectedResponse =
1207         Provider.newBuilder()
1208             .setName(ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]").toString())
1209             .setDisplayName("displayName1714148973")
1210             .addAllEventTypes(new ArrayList<EventType>())
1211             .build();
1212     mockService.addResponse(expectedResponse);
1213 
1214     String name = "projects/project-9368/locations/location-9368/providers/provider-9368";
1215 
1216     Provider actualResponse = client.getProvider(name);
1217     Assert.assertEquals(expectedResponse, actualResponse);
1218 
1219     List<String> actualRequests = mockService.getRequestPaths();
1220     Assert.assertEquals(1, actualRequests.size());
1221 
1222     String apiClientHeaderKey =
1223         mockService
1224             .getRequestHeaders()
1225             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1226             .iterator()
1227             .next();
1228     Assert.assertTrue(
1229         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1230             .matcher(apiClientHeaderKey)
1231             .matches());
1232   }
1233 
1234   @Test
getProviderExceptionTest2()1235   public void getProviderExceptionTest2() throws Exception {
1236     ApiException exception =
1237         ApiExceptionFactory.createException(
1238             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1239     mockService.addException(exception);
1240 
1241     try {
1242       String name = "projects/project-9368/locations/location-9368/providers/provider-9368";
1243       client.getProvider(name);
1244       Assert.fail("No exception raised");
1245     } catch (InvalidArgumentException e) {
1246       // Expected exception.
1247     }
1248   }
1249 
1250   @Test
listProvidersTest()1251   public void listProvidersTest() throws Exception {
1252     Provider responsesElement = Provider.newBuilder().build();
1253     ListProvidersResponse expectedResponse =
1254         ListProvidersResponse.newBuilder()
1255             .setNextPageToken("")
1256             .addAllProviders(Arrays.asList(responsesElement))
1257             .build();
1258     mockService.addResponse(expectedResponse);
1259 
1260     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1261 
1262     ListProvidersPagedResponse pagedListResponse = client.listProviders(parent);
1263 
1264     List<Provider> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1265 
1266     Assert.assertEquals(1, resources.size());
1267     Assert.assertEquals(expectedResponse.getProvidersList().get(0), resources.get(0));
1268 
1269     List<String> actualRequests = mockService.getRequestPaths();
1270     Assert.assertEquals(1, actualRequests.size());
1271 
1272     String apiClientHeaderKey =
1273         mockService
1274             .getRequestHeaders()
1275             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1276             .iterator()
1277             .next();
1278     Assert.assertTrue(
1279         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1280             .matcher(apiClientHeaderKey)
1281             .matches());
1282   }
1283 
1284   @Test
listProvidersExceptionTest()1285   public void listProvidersExceptionTest() throws Exception {
1286     ApiException exception =
1287         ApiExceptionFactory.createException(
1288             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1289     mockService.addException(exception);
1290 
1291     try {
1292       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1293       client.listProviders(parent);
1294       Assert.fail("No exception raised");
1295     } catch (InvalidArgumentException e) {
1296       // Expected exception.
1297     }
1298   }
1299 
1300   @Test
listProvidersTest2()1301   public void listProvidersTest2() throws Exception {
1302     Provider responsesElement = Provider.newBuilder().build();
1303     ListProvidersResponse expectedResponse =
1304         ListProvidersResponse.newBuilder()
1305             .setNextPageToken("")
1306             .addAllProviders(Arrays.asList(responsesElement))
1307             .build();
1308     mockService.addResponse(expectedResponse);
1309 
1310     String parent = "projects/project-5833/locations/location-5833";
1311 
1312     ListProvidersPagedResponse pagedListResponse = client.listProviders(parent);
1313 
1314     List<Provider> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1315 
1316     Assert.assertEquals(1, resources.size());
1317     Assert.assertEquals(expectedResponse.getProvidersList().get(0), resources.get(0));
1318 
1319     List<String> actualRequests = mockService.getRequestPaths();
1320     Assert.assertEquals(1, actualRequests.size());
1321 
1322     String apiClientHeaderKey =
1323         mockService
1324             .getRequestHeaders()
1325             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1326             .iterator()
1327             .next();
1328     Assert.assertTrue(
1329         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1330             .matcher(apiClientHeaderKey)
1331             .matches());
1332   }
1333 
1334   @Test
listProvidersExceptionTest2()1335   public void listProvidersExceptionTest2() throws Exception {
1336     ApiException exception =
1337         ApiExceptionFactory.createException(
1338             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1339     mockService.addException(exception);
1340 
1341     try {
1342       String parent = "projects/project-5833/locations/location-5833";
1343       client.listProviders(parent);
1344       Assert.fail("No exception raised");
1345     } catch (InvalidArgumentException e) {
1346       // Expected exception.
1347     }
1348   }
1349 
1350   @Test
getChannelConnectionTest()1351   public void getChannelConnectionTest() throws Exception {
1352     ChannelConnection expectedResponse =
1353         ChannelConnection.newBuilder()
1354             .setName(
1355                 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]")
1356                     .toString())
1357             .setUid("uid115792")
1358             .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1359             .setCreateTime(Timestamp.newBuilder().build())
1360             .setUpdateTime(Timestamp.newBuilder().build())
1361             .setActivationToken("activationToken1276937859")
1362             .build();
1363     mockService.addResponse(expectedResponse);
1364 
1365     ChannelConnectionName name =
1366         ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]");
1367 
1368     ChannelConnection actualResponse = client.getChannelConnection(name);
1369     Assert.assertEquals(expectedResponse, actualResponse);
1370 
1371     List<String> actualRequests = mockService.getRequestPaths();
1372     Assert.assertEquals(1, actualRequests.size());
1373 
1374     String apiClientHeaderKey =
1375         mockService
1376             .getRequestHeaders()
1377             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1378             .iterator()
1379             .next();
1380     Assert.assertTrue(
1381         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1382             .matcher(apiClientHeaderKey)
1383             .matches());
1384   }
1385 
1386   @Test
getChannelConnectionExceptionTest()1387   public void getChannelConnectionExceptionTest() throws Exception {
1388     ApiException exception =
1389         ApiExceptionFactory.createException(
1390             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1391     mockService.addException(exception);
1392 
1393     try {
1394       ChannelConnectionName name =
1395           ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]");
1396       client.getChannelConnection(name);
1397       Assert.fail("No exception raised");
1398     } catch (InvalidArgumentException e) {
1399       // Expected exception.
1400     }
1401   }
1402 
1403   @Test
getChannelConnectionTest2()1404   public void getChannelConnectionTest2() throws Exception {
1405     ChannelConnection expectedResponse =
1406         ChannelConnection.newBuilder()
1407             .setName(
1408                 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]")
1409                     .toString())
1410             .setUid("uid115792")
1411             .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1412             .setCreateTime(Timestamp.newBuilder().build())
1413             .setUpdateTime(Timestamp.newBuilder().build())
1414             .setActivationToken("activationToken1276937859")
1415             .build();
1416     mockService.addResponse(expectedResponse);
1417 
1418     String name =
1419         "projects/project-8642/locations/location-8642/channelConnections/channelConnection-8642";
1420 
1421     ChannelConnection actualResponse = client.getChannelConnection(name);
1422     Assert.assertEquals(expectedResponse, actualResponse);
1423 
1424     List<String> actualRequests = mockService.getRequestPaths();
1425     Assert.assertEquals(1, actualRequests.size());
1426 
1427     String apiClientHeaderKey =
1428         mockService
1429             .getRequestHeaders()
1430             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1431             .iterator()
1432             .next();
1433     Assert.assertTrue(
1434         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1435             .matcher(apiClientHeaderKey)
1436             .matches());
1437   }
1438 
1439   @Test
getChannelConnectionExceptionTest2()1440   public void getChannelConnectionExceptionTest2() throws Exception {
1441     ApiException exception =
1442         ApiExceptionFactory.createException(
1443             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1444     mockService.addException(exception);
1445 
1446     try {
1447       String name =
1448           "projects/project-8642/locations/location-8642/channelConnections/channelConnection-8642";
1449       client.getChannelConnection(name);
1450       Assert.fail("No exception raised");
1451     } catch (InvalidArgumentException e) {
1452       // Expected exception.
1453     }
1454   }
1455 
1456   @Test
listChannelConnectionsTest()1457   public void listChannelConnectionsTest() throws Exception {
1458     ChannelConnection responsesElement = ChannelConnection.newBuilder().build();
1459     ListChannelConnectionsResponse expectedResponse =
1460         ListChannelConnectionsResponse.newBuilder()
1461             .setNextPageToken("")
1462             .addAllChannelConnections(Arrays.asList(responsesElement))
1463             .build();
1464     mockService.addResponse(expectedResponse);
1465 
1466     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1467 
1468     ListChannelConnectionsPagedResponse pagedListResponse = client.listChannelConnections(parent);
1469 
1470     List<ChannelConnection> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1471 
1472     Assert.assertEquals(1, resources.size());
1473     Assert.assertEquals(expectedResponse.getChannelConnectionsList().get(0), resources.get(0));
1474 
1475     List<String> actualRequests = mockService.getRequestPaths();
1476     Assert.assertEquals(1, actualRequests.size());
1477 
1478     String apiClientHeaderKey =
1479         mockService
1480             .getRequestHeaders()
1481             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1482             .iterator()
1483             .next();
1484     Assert.assertTrue(
1485         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1486             .matcher(apiClientHeaderKey)
1487             .matches());
1488   }
1489 
1490   @Test
listChannelConnectionsExceptionTest()1491   public void listChannelConnectionsExceptionTest() throws Exception {
1492     ApiException exception =
1493         ApiExceptionFactory.createException(
1494             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1495     mockService.addException(exception);
1496 
1497     try {
1498       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1499       client.listChannelConnections(parent);
1500       Assert.fail("No exception raised");
1501     } catch (InvalidArgumentException e) {
1502       // Expected exception.
1503     }
1504   }
1505 
1506   @Test
listChannelConnectionsTest2()1507   public void listChannelConnectionsTest2() throws Exception {
1508     ChannelConnection responsesElement = ChannelConnection.newBuilder().build();
1509     ListChannelConnectionsResponse expectedResponse =
1510         ListChannelConnectionsResponse.newBuilder()
1511             .setNextPageToken("")
1512             .addAllChannelConnections(Arrays.asList(responsesElement))
1513             .build();
1514     mockService.addResponse(expectedResponse);
1515 
1516     String parent = "projects/project-5833/locations/location-5833";
1517 
1518     ListChannelConnectionsPagedResponse pagedListResponse = client.listChannelConnections(parent);
1519 
1520     List<ChannelConnection> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1521 
1522     Assert.assertEquals(1, resources.size());
1523     Assert.assertEquals(expectedResponse.getChannelConnectionsList().get(0), resources.get(0));
1524 
1525     List<String> actualRequests = mockService.getRequestPaths();
1526     Assert.assertEquals(1, actualRequests.size());
1527 
1528     String apiClientHeaderKey =
1529         mockService
1530             .getRequestHeaders()
1531             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1532             .iterator()
1533             .next();
1534     Assert.assertTrue(
1535         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1536             .matcher(apiClientHeaderKey)
1537             .matches());
1538   }
1539 
1540   @Test
listChannelConnectionsExceptionTest2()1541   public void listChannelConnectionsExceptionTest2() throws Exception {
1542     ApiException exception =
1543         ApiExceptionFactory.createException(
1544             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1545     mockService.addException(exception);
1546 
1547     try {
1548       String parent = "projects/project-5833/locations/location-5833";
1549       client.listChannelConnections(parent);
1550       Assert.fail("No exception raised");
1551     } catch (InvalidArgumentException e) {
1552       // Expected exception.
1553     }
1554   }
1555 
1556   @Test
createChannelConnectionTest()1557   public void createChannelConnectionTest() throws Exception {
1558     ChannelConnection expectedResponse =
1559         ChannelConnection.newBuilder()
1560             .setName(
1561                 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]")
1562                     .toString())
1563             .setUid("uid115792")
1564             .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1565             .setCreateTime(Timestamp.newBuilder().build())
1566             .setUpdateTime(Timestamp.newBuilder().build())
1567             .setActivationToken("activationToken1276937859")
1568             .build();
1569     Operation resultOperation =
1570         Operation.newBuilder()
1571             .setName("createChannelConnectionTest")
1572             .setDone(true)
1573             .setResponse(Any.pack(expectedResponse))
1574             .build();
1575     mockService.addResponse(resultOperation);
1576 
1577     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1578     ChannelConnection channelConnection = ChannelConnection.newBuilder().build();
1579     String channelConnectionId = "channelConnectionId-1246974660";
1580 
1581     ChannelConnection actualResponse =
1582         client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get();
1583     Assert.assertEquals(expectedResponse, actualResponse);
1584 
1585     List<String> actualRequests = mockService.getRequestPaths();
1586     Assert.assertEquals(1, actualRequests.size());
1587 
1588     String apiClientHeaderKey =
1589         mockService
1590             .getRequestHeaders()
1591             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1592             .iterator()
1593             .next();
1594     Assert.assertTrue(
1595         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1596             .matcher(apiClientHeaderKey)
1597             .matches());
1598   }
1599 
1600   @Test
createChannelConnectionExceptionTest()1601   public void createChannelConnectionExceptionTest() throws Exception {
1602     ApiException exception =
1603         ApiExceptionFactory.createException(
1604             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1605     mockService.addException(exception);
1606 
1607     try {
1608       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1609       ChannelConnection channelConnection = ChannelConnection.newBuilder().build();
1610       String channelConnectionId = "channelConnectionId-1246974660";
1611       client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get();
1612       Assert.fail("No exception raised");
1613     } catch (ExecutionException e) {
1614     }
1615   }
1616 
1617   @Test
createChannelConnectionTest2()1618   public void createChannelConnectionTest2() throws Exception {
1619     ChannelConnection expectedResponse =
1620         ChannelConnection.newBuilder()
1621             .setName(
1622                 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]")
1623                     .toString())
1624             .setUid("uid115792")
1625             .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1626             .setCreateTime(Timestamp.newBuilder().build())
1627             .setUpdateTime(Timestamp.newBuilder().build())
1628             .setActivationToken("activationToken1276937859")
1629             .build();
1630     Operation resultOperation =
1631         Operation.newBuilder()
1632             .setName("createChannelConnectionTest")
1633             .setDone(true)
1634             .setResponse(Any.pack(expectedResponse))
1635             .build();
1636     mockService.addResponse(resultOperation);
1637 
1638     String parent = "projects/project-5833/locations/location-5833";
1639     ChannelConnection channelConnection = ChannelConnection.newBuilder().build();
1640     String channelConnectionId = "channelConnectionId-1246974660";
1641 
1642     ChannelConnection actualResponse =
1643         client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get();
1644     Assert.assertEquals(expectedResponse, actualResponse);
1645 
1646     List<String> actualRequests = mockService.getRequestPaths();
1647     Assert.assertEquals(1, actualRequests.size());
1648 
1649     String apiClientHeaderKey =
1650         mockService
1651             .getRequestHeaders()
1652             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1653             .iterator()
1654             .next();
1655     Assert.assertTrue(
1656         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1657             .matcher(apiClientHeaderKey)
1658             .matches());
1659   }
1660 
1661   @Test
createChannelConnectionExceptionTest2()1662   public void createChannelConnectionExceptionTest2() throws Exception {
1663     ApiException exception =
1664         ApiExceptionFactory.createException(
1665             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1666     mockService.addException(exception);
1667 
1668     try {
1669       String parent = "projects/project-5833/locations/location-5833";
1670       ChannelConnection channelConnection = ChannelConnection.newBuilder().build();
1671       String channelConnectionId = "channelConnectionId-1246974660";
1672       client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get();
1673       Assert.fail("No exception raised");
1674     } catch (ExecutionException e) {
1675     }
1676   }
1677 
1678   @Test
deleteChannelConnectionTest()1679   public void deleteChannelConnectionTest() throws Exception {
1680     ChannelConnection expectedResponse =
1681         ChannelConnection.newBuilder()
1682             .setName(
1683                 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]")
1684                     .toString())
1685             .setUid("uid115792")
1686             .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1687             .setCreateTime(Timestamp.newBuilder().build())
1688             .setUpdateTime(Timestamp.newBuilder().build())
1689             .setActivationToken("activationToken1276937859")
1690             .build();
1691     Operation resultOperation =
1692         Operation.newBuilder()
1693             .setName("deleteChannelConnectionTest")
1694             .setDone(true)
1695             .setResponse(Any.pack(expectedResponse))
1696             .build();
1697     mockService.addResponse(resultOperation);
1698 
1699     ChannelConnectionName name =
1700         ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]");
1701 
1702     ChannelConnection actualResponse = client.deleteChannelConnectionAsync(name).get();
1703     Assert.assertEquals(expectedResponse, actualResponse);
1704 
1705     List<String> actualRequests = mockService.getRequestPaths();
1706     Assert.assertEquals(1, actualRequests.size());
1707 
1708     String apiClientHeaderKey =
1709         mockService
1710             .getRequestHeaders()
1711             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1712             .iterator()
1713             .next();
1714     Assert.assertTrue(
1715         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1716             .matcher(apiClientHeaderKey)
1717             .matches());
1718   }
1719 
1720   @Test
deleteChannelConnectionExceptionTest()1721   public void deleteChannelConnectionExceptionTest() throws Exception {
1722     ApiException exception =
1723         ApiExceptionFactory.createException(
1724             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1725     mockService.addException(exception);
1726 
1727     try {
1728       ChannelConnectionName name =
1729           ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]");
1730       client.deleteChannelConnectionAsync(name).get();
1731       Assert.fail("No exception raised");
1732     } catch (ExecutionException e) {
1733     }
1734   }
1735 
1736   @Test
deleteChannelConnectionTest2()1737   public void deleteChannelConnectionTest2() throws Exception {
1738     ChannelConnection expectedResponse =
1739         ChannelConnection.newBuilder()
1740             .setName(
1741                 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]")
1742                     .toString())
1743             .setUid("uid115792")
1744             .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
1745             .setCreateTime(Timestamp.newBuilder().build())
1746             .setUpdateTime(Timestamp.newBuilder().build())
1747             .setActivationToken("activationToken1276937859")
1748             .build();
1749     Operation resultOperation =
1750         Operation.newBuilder()
1751             .setName("deleteChannelConnectionTest")
1752             .setDone(true)
1753             .setResponse(Any.pack(expectedResponse))
1754             .build();
1755     mockService.addResponse(resultOperation);
1756 
1757     String name =
1758         "projects/project-8642/locations/location-8642/channelConnections/channelConnection-8642";
1759 
1760     ChannelConnection actualResponse = client.deleteChannelConnectionAsync(name).get();
1761     Assert.assertEquals(expectedResponse, actualResponse);
1762 
1763     List<String> actualRequests = mockService.getRequestPaths();
1764     Assert.assertEquals(1, actualRequests.size());
1765 
1766     String apiClientHeaderKey =
1767         mockService
1768             .getRequestHeaders()
1769             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1770             .iterator()
1771             .next();
1772     Assert.assertTrue(
1773         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1774             .matcher(apiClientHeaderKey)
1775             .matches());
1776   }
1777 
1778   @Test
deleteChannelConnectionExceptionTest2()1779   public void deleteChannelConnectionExceptionTest2() throws Exception {
1780     ApiException exception =
1781         ApiExceptionFactory.createException(
1782             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1783     mockService.addException(exception);
1784 
1785     try {
1786       String name =
1787           "projects/project-8642/locations/location-8642/channelConnections/channelConnection-8642";
1788       client.deleteChannelConnectionAsync(name).get();
1789       Assert.fail("No exception raised");
1790     } catch (ExecutionException e) {
1791     }
1792   }
1793 
1794   @Test
getGoogleChannelConfigTest()1795   public void getGoogleChannelConfigTest() throws Exception {
1796     GoogleChannelConfig expectedResponse =
1797         GoogleChannelConfig.newBuilder()
1798             .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString())
1799             .setUpdateTime(Timestamp.newBuilder().build())
1800             .setCryptoKeyName("cryptoKeyName1447084425")
1801             .build();
1802     mockService.addResponse(expectedResponse);
1803 
1804     GoogleChannelConfigName name = GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]");
1805 
1806     GoogleChannelConfig actualResponse = client.getGoogleChannelConfig(name);
1807     Assert.assertEquals(expectedResponse, actualResponse);
1808 
1809     List<String> actualRequests = mockService.getRequestPaths();
1810     Assert.assertEquals(1, actualRequests.size());
1811 
1812     String apiClientHeaderKey =
1813         mockService
1814             .getRequestHeaders()
1815             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1816             .iterator()
1817             .next();
1818     Assert.assertTrue(
1819         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1820             .matcher(apiClientHeaderKey)
1821             .matches());
1822   }
1823 
1824   @Test
getGoogleChannelConfigExceptionTest()1825   public void getGoogleChannelConfigExceptionTest() throws Exception {
1826     ApiException exception =
1827         ApiExceptionFactory.createException(
1828             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1829     mockService.addException(exception);
1830 
1831     try {
1832       GoogleChannelConfigName name = GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]");
1833       client.getGoogleChannelConfig(name);
1834       Assert.fail("No exception raised");
1835     } catch (InvalidArgumentException e) {
1836       // Expected exception.
1837     }
1838   }
1839 
1840   @Test
getGoogleChannelConfigTest2()1841   public void getGoogleChannelConfigTest2() throws Exception {
1842     GoogleChannelConfig expectedResponse =
1843         GoogleChannelConfig.newBuilder()
1844             .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString())
1845             .setUpdateTime(Timestamp.newBuilder().build())
1846             .setCryptoKeyName("cryptoKeyName1447084425")
1847             .build();
1848     mockService.addResponse(expectedResponse);
1849 
1850     String name = "projects/project-4921/locations/location-4921/googleChannelConfig";
1851 
1852     GoogleChannelConfig actualResponse = client.getGoogleChannelConfig(name);
1853     Assert.assertEquals(expectedResponse, actualResponse);
1854 
1855     List<String> actualRequests = mockService.getRequestPaths();
1856     Assert.assertEquals(1, actualRequests.size());
1857 
1858     String apiClientHeaderKey =
1859         mockService
1860             .getRequestHeaders()
1861             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1862             .iterator()
1863             .next();
1864     Assert.assertTrue(
1865         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1866             .matcher(apiClientHeaderKey)
1867             .matches());
1868   }
1869 
1870   @Test
getGoogleChannelConfigExceptionTest2()1871   public void getGoogleChannelConfigExceptionTest2() throws Exception {
1872     ApiException exception =
1873         ApiExceptionFactory.createException(
1874             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1875     mockService.addException(exception);
1876 
1877     try {
1878       String name = "projects/project-4921/locations/location-4921/googleChannelConfig";
1879       client.getGoogleChannelConfig(name);
1880       Assert.fail("No exception raised");
1881     } catch (InvalidArgumentException e) {
1882       // Expected exception.
1883     }
1884   }
1885 
1886   @Test
updateGoogleChannelConfigTest()1887   public void updateGoogleChannelConfigTest() throws Exception {
1888     GoogleChannelConfig expectedResponse =
1889         GoogleChannelConfig.newBuilder()
1890             .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString())
1891             .setUpdateTime(Timestamp.newBuilder().build())
1892             .setCryptoKeyName("cryptoKeyName1447084425")
1893             .build();
1894     mockService.addResponse(expectedResponse);
1895 
1896     GoogleChannelConfig googleChannelConfig =
1897         GoogleChannelConfig.newBuilder()
1898             .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString())
1899             .setUpdateTime(Timestamp.newBuilder().build())
1900             .setCryptoKeyName("cryptoKeyName1447084425")
1901             .build();
1902     FieldMask updateMask = FieldMask.newBuilder().build();
1903 
1904     GoogleChannelConfig actualResponse =
1905         client.updateGoogleChannelConfig(googleChannelConfig, updateMask);
1906     Assert.assertEquals(expectedResponse, actualResponse);
1907 
1908     List<String> actualRequests = mockService.getRequestPaths();
1909     Assert.assertEquals(1, actualRequests.size());
1910 
1911     String apiClientHeaderKey =
1912         mockService
1913             .getRequestHeaders()
1914             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1915             .iterator()
1916             .next();
1917     Assert.assertTrue(
1918         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1919             .matcher(apiClientHeaderKey)
1920             .matches());
1921   }
1922 
1923   @Test
updateGoogleChannelConfigExceptionTest()1924   public void updateGoogleChannelConfigExceptionTest() throws Exception {
1925     ApiException exception =
1926         ApiExceptionFactory.createException(
1927             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1928     mockService.addException(exception);
1929 
1930     try {
1931       GoogleChannelConfig googleChannelConfig =
1932           GoogleChannelConfig.newBuilder()
1933               .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString())
1934               .setUpdateTime(Timestamp.newBuilder().build())
1935               .setCryptoKeyName("cryptoKeyName1447084425")
1936               .build();
1937       FieldMask updateMask = FieldMask.newBuilder().build();
1938       client.updateGoogleChannelConfig(googleChannelConfig, updateMask);
1939       Assert.fail("No exception raised");
1940     } catch (InvalidArgumentException e) {
1941       // Expected exception.
1942     }
1943   }
1944 
1945   @Test
listLocationsTest()1946   public void listLocationsTest() throws Exception {
1947     Location responsesElement = Location.newBuilder().build();
1948     ListLocationsResponse expectedResponse =
1949         ListLocationsResponse.newBuilder()
1950             .setNextPageToken("")
1951             .addAllLocations(Arrays.asList(responsesElement))
1952             .build();
1953     mockService.addResponse(expectedResponse);
1954 
1955     ListLocationsRequest request =
1956         ListLocationsRequest.newBuilder()
1957             .setName("projects/project-3664")
1958             .setFilter("filter-1274492040")
1959             .setPageSize(883849137)
1960             .setPageToken("pageToken873572522")
1961             .build();
1962 
1963     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
1964 
1965     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1966 
1967     Assert.assertEquals(1, resources.size());
1968     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
1969 
1970     List<String> actualRequests = mockService.getRequestPaths();
1971     Assert.assertEquals(1, actualRequests.size());
1972 
1973     String apiClientHeaderKey =
1974         mockService
1975             .getRequestHeaders()
1976             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1977             .iterator()
1978             .next();
1979     Assert.assertTrue(
1980         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1981             .matcher(apiClientHeaderKey)
1982             .matches());
1983   }
1984 
1985   @Test
listLocationsExceptionTest()1986   public void listLocationsExceptionTest() throws Exception {
1987     ApiException exception =
1988         ApiExceptionFactory.createException(
1989             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1990     mockService.addException(exception);
1991 
1992     try {
1993       ListLocationsRequest request =
1994           ListLocationsRequest.newBuilder()
1995               .setName("projects/project-3664")
1996               .setFilter("filter-1274492040")
1997               .setPageSize(883849137)
1998               .setPageToken("pageToken873572522")
1999               .build();
2000       client.listLocations(request);
2001       Assert.fail("No exception raised");
2002     } catch (InvalidArgumentException e) {
2003       // Expected exception.
2004     }
2005   }
2006 
2007   @Test
getLocationTest()2008   public void getLocationTest() throws Exception {
2009     Location expectedResponse =
2010         Location.newBuilder()
2011             .setName("name3373707")
2012             .setLocationId("locationId1541836720")
2013             .setDisplayName("displayName1714148973")
2014             .putAllLabels(new HashMap<String, String>())
2015             .setMetadata(Any.newBuilder().build())
2016             .build();
2017     mockService.addResponse(expectedResponse);
2018 
2019     GetLocationRequest request =
2020         GetLocationRequest.newBuilder()
2021             .setName("projects/project-9062/locations/location-9062")
2022             .build();
2023 
2024     Location actualResponse = client.getLocation(request);
2025     Assert.assertEquals(expectedResponse, actualResponse);
2026 
2027     List<String> actualRequests = mockService.getRequestPaths();
2028     Assert.assertEquals(1, actualRequests.size());
2029 
2030     String apiClientHeaderKey =
2031         mockService
2032             .getRequestHeaders()
2033             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2034             .iterator()
2035             .next();
2036     Assert.assertTrue(
2037         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2038             .matcher(apiClientHeaderKey)
2039             .matches());
2040   }
2041 
2042   @Test
getLocationExceptionTest()2043   public void getLocationExceptionTest() throws Exception {
2044     ApiException exception =
2045         ApiExceptionFactory.createException(
2046             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2047     mockService.addException(exception);
2048 
2049     try {
2050       GetLocationRequest request =
2051           GetLocationRequest.newBuilder()
2052               .setName("projects/project-9062/locations/location-9062")
2053               .build();
2054       client.getLocation(request);
2055       Assert.fail("No exception raised");
2056     } catch (InvalidArgumentException e) {
2057       // Expected exception.
2058     }
2059   }
2060 
2061   @Test
setIamPolicyTest()2062   public void setIamPolicyTest() throws Exception {
2063     Policy expectedResponse =
2064         Policy.newBuilder()
2065             .setVersion(351608024)
2066             .addAllBindings(new ArrayList<Binding>())
2067             .addAllAuditConfigs(new ArrayList<AuditConfig>())
2068             .setEtag(ByteString.EMPTY)
2069             .build();
2070     mockService.addResponse(expectedResponse);
2071 
2072     SetIamPolicyRequest request =
2073         SetIamPolicyRequest.newBuilder()
2074             .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
2075             .setPolicy(Policy.newBuilder().build())
2076             .setUpdateMask(FieldMask.newBuilder().build())
2077             .build();
2078 
2079     Policy actualResponse = client.setIamPolicy(request);
2080     Assert.assertEquals(expectedResponse, actualResponse);
2081 
2082     List<String> actualRequests = mockService.getRequestPaths();
2083     Assert.assertEquals(1, actualRequests.size());
2084 
2085     String apiClientHeaderKey =
2086         mockService
2087             .getRequestHeaders()
2088             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2089             .iterator()
2090             .next();
2091     Assert.assertTrue(
2092         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2093             .matcher(apiClientHeaderKey)
2094             .matches());
2095   }
2096 
2097   @Test
setIamPolicyExceptionTest()2098   public void setIamPolicyExceptionTest() throws Exception {
2099     ApiException exception =
2100         ApiExceptionFactory.createException(
2101             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2102     mockService.addException(exception);
2103 
2104     try {
2105       SetIamPolicyRequest request =
2106           SetIamPolicyRequest.newBuilder()
2107               .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
2108               .setPolicy(Policy.newBuilder().build())
2109               .setUpdateMask(FieldMask.newBuilder().build())
2110               .build();
2111       client.setIamPolicy(request);
2112       Assert.fail("No exception raised");
2113     } catch (InvalidArgumentException e) {
2114       // Expected exception.
2115     }
2116   }
2117 
2118   @Test
getIamPolicyTest()2119   public void getIamPolicyTest() throws Exception {
2120     Policy expectedResponse =
2121         Policy.newBuilder()
2122             .setVersion(351608024)
2123             .addAllBindings(new ArrayList<Binding>())
2124             .addAllAuditConfigs(new ArrayList<AuditConfig>())
2125             .setEtag(ByteString.EMPTY)
2126             .build();
2127     mockService.addResponse(expectedResponse);
2128 
2129     GetIamPolicyRequest request =
2130         GetIamPolicyRequest.newBuilder()
2131             .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
2132             .setOptions(GetPolicyOptions.newBuilder().build())
2133             .build();
2134 
2135     Policy actualResponse = client.getIamPolicy(request);
2136     Assert.assertEquals(expectedResponse, actualResponse);
2137 
2138     List<String> actualRequests = mockService.getRequestPaths();
2139     Assert.assertEquals(1, actualRequests.size());
2140 
2141     String apiClientHeaderKey =
2142         mockService
2143             .getRequestHeaders()
2144             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2145             .iterator()
2146             .next();
2147     Assert.assertTrue(
2148         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2149             .matcher(apiClientHeaderKey)
2150             .matches());
2151   }
2152 
2153   @Test
getIamPolicyExceptionTest()2154   public void getIamPolicyExceptionTest() throws Exception {
2155     ApiException exception =
2156         ApiExceptionFactory.createException(
2157             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2158     mockService.addException(exception);
2159 
2160     try {
2161       GetIamPolicyRequest request =
2162           GetIamPolicyRequest.newBuilder()
2163               .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
2164               .setOptions(GetPolicyOptions.newBuilder().build())
2165               .build();
2166       client.getIamPolicy(request);
2167       Assert.fail("No exception raised");
2168     } catch (InvalidArgumentException e) {
2169       // Expected exception.
2170     }
2171   }
2172 
2173   @Test
testIamPermissionsTest()2174   public void testIamPermissionsTest() throws Exception {
2175     TestIamPermissionsResponse expectedResponse =
2176         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
2177     mockService.addResponse(expectedResponse);
2178 
2179     TestIamPermissionsRequest request =
2180         TestIamPermissionsRequest.newBuilder()
2181             .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
2182             .addAllPermissions(new ArrayList<String>())
2183             .build();
2184 
2185     TestIamPermissionsResponse actualResponse = client.testIamPermissions(request);
2186     Assert.assertEquals(expectedResponse, actualResponse);
2187 
2188     List<String> actualRequests = mockService.getRequestPaths();
2189     Assert.assertEquals(1, actualRequests.size());
2190 
2191     String apiClientHeaderKey =
2192         mockService
2193             .getRequestHeaders()
2194             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2195             .iterator()
2196             .next();
2197     Assert.assertTrue(
2198         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2199             .matcher(apiClientHeaderKey)
2200             .matches());
2201   }
2202 
2203   @Test
testIamPermissionsExceptionTest()2204   public void testIamPermissionsExceptionTest() throws Exception {
2205     ApiException exception =
2206         ApiExceptionFactory.createException(
2207             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2208     mockService.addException(exception);
2209 
2210     try {
2211       TestIamPermissionsRequest request =
2212           TestIamPermissionsRequest.newBuilder()
2213               .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString())
2214               .addAllPermissions(new ArrayList<String>())
2215               .build();
2216       client.testIamPermissions(request);
2217       Assert.fail("No exception raised");
2218     } catch (InvalidArgumentException e) {
2219       // Expected exception.
2220     }
2221   }
2222 }
2223