• 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.monitoring.v3;
18 
19 import static com.google.cloud.monitoring.v3.NotificationChannelServiceClient.ListNotificationChannelDescriptorsPagedResponse;
20 import static com.google.cloud.monitoring.v3.NotificationChannelServiceClient.ListNotificationChannelsPagedResponse;
21 
22 import com.google.api.LabelDescriptor;
23 import com.google.api.LaunchStage;
24 import com.google.api.gax.core.NoCredentialsProvider;
25 import com.google.api.gax.grpc.GaxGrpcProperties;
26 import com.google.api.gax.grpc.testing.LocalChannelProvider;
27 import com.google.api.gax.grpc.testing.MockGrpcService;
28 import com.google.api.gax.grpc.testing.MockServiceHelper;
29 import com.google.api.gax.rpc.ApiClientHeaderProvider;
30 import com.google.api.gax.rpc.InvalidArgumentException;
31 import com.google.common.collect.Lists;
32 import com.google.monitoring.v3.CreateNotificationChannelRequest;
33 import com.google.monitoring.v3.DeleteNotificationChannelRequest;
34 import com.google.monitoring.v3.FolderName;
35 import com.google.monitoring.v3.GetNotificationChannelDescriptorRequest;
36 import com.google.monitoring.v3.GetNotificationChannelRequest;
37 import com.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest;
38 import com.google.monitoring.v3.GetNotificationChannelVerificationCodeResponse;
39 import com.google.monitoring.v3.ListNotificationChannelDescriptorsRequest;
40 import com.google.monitoring.v3.ListNotificationChannelDescriptorsResponse;
41 import com.google.monitoring.v3.ListNotificationChannelsRequest;
42 import com.google.monitoring.v3.ListNotificationChannelsResponse;
43 import com.google.monitoring.v3.MutationRecord;
44 import com.google.monitoring.v3.NotificationChannel;
45 import com.google.monitoring.v3.NotificationChannelDescriptor;
46 import com.google.monitoring.v3.NotificationChannelDescriptorName;
47 import com.google.monitoring.v3.NotificationChannelName;
48 import com.google.monitoring.v3.OrganizationName;
49 import com.google.monitoring.v3.ProjectName;
50 import com.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest;
51 import com.google.monitoring.v3.ServiceTier;
52 import com.google.monitoring.v3.UpdateNotificationChannelRequest;
53 import com.google.monitoring.v3.VerifyNotificationChannelRequest;
54 import com.google.protobuf.AbstractMessage;
55 import com.google.protobuf.BoolValue;
56 import com.google.protobuf.Empty;
57 import com.google.protobuf.FieldMask;
58 import com.google.protobuf.Timestamp;
59 import io.grpc.StatusRuntimeException;
60 import java.io.IOException;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.HashMap;
64 import java.util.List;
65 import java.util.UUID;
66 import javax.annotation.Generated;
67 import org.junit.After;
68 import org.junit.AfterClass;
69 import org.junit.Assert;
70 import org.junit.Before;
71 import org.junit.BeforeClass;
72 import org.junit.Test;
73 
74 @Generated("by gapic-generator-java")
75 public class NotificationChannelServiceClientTest {
76   private static MockNotificationChannelService mockNotificationChannelService;
77   private static MockServiceHelper mockServiceHelper;
78   private LocalChannelProvider channelProvider;
79   private NotificationChannelServiceClient client;
80 
81   @BeforeClass
startStaticServer()82   public static void startStaticServer() {
83     mockNotificationChannelService = new MockNotificationChannelService();
84     mockServiceHelper =
85         new MockServiceHelper(
86             UUID.randomUUID().toString(),
87             Arrays.<MockGrpcService>asList(mockNotificationChannelService));
88     mockServiceHelper.start();
89   }
90 
91   @AfterClass
stopServer()92   public static void stopServer() {
93     mockServiceHelper.stop();
94   }
95 
96   @Before
setUp()97   public void setUp() throws IOException {
98     mockServiceHelper.reset();
99     channelProvider = mockServiceHelper.createChannelProvider();
100     NotificationChannelServiceSettings settings =
101         NotificationChannelServiceSettings.newBuilder()
102             .setTransportChannelProvider(channelProvider)
103             .setCredentialsProvider(NoCredentialsProvider.create())
104             .build();
105     client = NotificationChannelServiceClient.create(settings);
106   }
107 
108   @After
tearDown()109   public void tearDown() throws Exception {
110     client.close();
111   }
112 
113   @Test
listNotificationChannelDescriptorsTest()114   public void listNotificationChannelDescriptorsTest() throws Exception {
115     NotificationChannelDescriptor responsesElement =
116         NotificationChannelDescriptor.newBuilder().build();
117     ListNotificationChannelDescriptorsResponse expectedResponse =
118         ListNotificationChannelDescriptorsResponse.newBuilder()
119             .setNextPageToken("")
120             .addAllChannelDescriptors(Arrays.asList(responsesElement))
121             .build();
122     mockNotificationChannelService.addResponse(expectedResponse);
123 
124     FolderName name = FolderName.of("[FOLDER]");
125 
126     ListNotificationChannelDescriptorsPagedResponse pagedListResponse =
127         client.listNotificationChannelDescriptors(name);
128 
129     List<NotificationChannelDescriptor> resources =
130         Lists.newArrayList(pagedListResponse.iterateAll());
131 
132     Assert.assertEquals(1, resources.size());
133     Assert.assertEquals(expectedResponse.getChannelDescriptorsList().get(0), resources.get(0));
134 
135     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
136     Assert.assertEquals(1, actualRequests.size());
137     ListNotificationChannelDescriptorsRequest actualRequest =
138         ((ListNotificationChannelDescriptorsRequest) actualRequests.get(0));
139 
140     Assert.assertEquals(name.toString(), actualRequest.getName());
141     Assert.assertTrue(
142         channelProvider.isHeaderSent(
143             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
144             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
145   }
146 
147   @Test
listNotificationChannelDescriptorsExceptionTest()148   public void listNotificationChannelDescriptorsExceptionTest() throws Exception {
149     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
150     mockNotificationChannelService.addException(exception);
151 
152     try {
153       FolderName name = FolderName.of("[FOLDER]");
154       client.listNotificationChannelDescriptors(name);
155       Assert.fail("No exception raised");
156     } catch (InvalidArgumentException e) {
157       // Expected exception.
158     }
159   }
160 
161   @Test
listNotificationChannelDescriptorsTest2()162   public void listNotificationChannelDescriptorsTest2() throws Exception {
163     NotificationChannelDescriptor responsesElement =
164         NotificationChannelDescriptor.newBuilder().build();
165     ListNotificationChannelDescriptorsResponse expectedResponse =
166         ListNotificationChannelDescriptorsResponse.newBuilder()
167             .setNextPageToken("")
168             .addAllChannelDescriptors(Arrays.asList(responsesElement))
169             .build();
170     mockNotificationChannelService.addResponse(expectedResponse);
171 
172     OrganizationName name = OrganizationName.of("[ORGANIZATION]");
173 
174     ListNotificationChannelDescriptorsPagedResponse pagedListResponse =
175         client.listNotificationChannelDescriptors(name);
176 
177     List<NotificationChannelDescriptor> resources =
178         Lists.newArrayList(pagedListResponse.iterateAll());
179 
180     Assert.assertEquals(1, resources.size());
181     Assert.assertEquals(expectedResponse.getChannelDescriptorsList().get(0), resources.get(0));
182 
183     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
184     Assert.assertEquals(1, actualRequests.size());
185     ListNotificationChannelDescriptorsRequest actualRequest =
186         ((ListNotificationChannelDescriptorsRequest) actualRequests.get(0));
187 
188     Assert.assertEquals(name.toString(), actualRequest.getName());
189     Assert.assertTrue(
190         channelProvider.isHeaderSent(
191             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
192             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
193   }
194 
195   @Test
listNotificationChannelDescriptorsExceptionTest2()196   public void listNotificationChannelDescriptorsExceptionTest2() throws Exception {
197     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
198     mockNotificationChannelService.addException(exception);
199 
200     try {
201       OrganizationName name = OrganizationName.of("[ORGANIZATION]");
202       client.listNotificationChannelDescriptors(name);
203       Assert.fail("No exception raised");
204     } catch (InvalidArgumentException e) {
205       // Expected exception.
206     }
207   }
208 
209   @Test
listNotificationChannelDescriptorsTest3()210   public void listNotificationChannelDescriptorsTest3() throws Exception {
211     NotificationChannelDescriptor responsesElement =
212         NotificationChannelDescriptor.newBuilder().build();
213     ListNotificationChannelDescriptorsResponse expectedResponse =
214         ListNotificationChannelDescriptorsResponse.newBuilder()
215             .setNextPageToken("")
216             .addAllChannelDescriptors(Arrays.asList(responsesElement))
217             .build();
218     mockNotificationChannelService.addResponse(expectedResponse);
219 
220     ProjectName name = ProjectName.of("[PROJECT]");
221 
222     ListNotificationChannelDescriptorsPagedResponse pagedListResponse =
223         client.listNotificationChannelDescriptors(name);
224 
225     List<NotificationChannelDescriptor> resources =
226         Lists.newArrayList(pagedListResponse.iterateAll());
227 
228     Assert.assertEquals(1, resources.size());
229     Assert.assertEquals(expectedResponse.getChannelDescriptorsList().get(0), resources.get(0));
230 
231     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
232     Assert.assertEquals(1, actualRequests.size());
233     ListNotificationChannelDescriptorsRequest actualRequest =
234         ((ListNotificationChannelDescriptorsRequest) actualRequests.get(0));
235 
236     Assert.assertEquals(name.toString(), actualRequest.getName());
237     Assert.assertTrue(
238         channelProvider.isHeaderSent(
239             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
240             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
241   }
242 
243   @Test
listNotificationChannelDescriptorsExceptionTest3()244   public void listNotificationChannelDescriptorsExceptionTest3() throws Exception {
245     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
246     mockNotificationChannelService.addException(exception);
247 
248     try {
249       ProjectName name = ProjectName.of("[PROJECT]");
250       client.listNotificationChannelDescriptors(name);
251       Assert.fail("No exception raised");
252     } catch (InvalidArgumentException e) {
253       // Expected exception.
254     }
255   }
256 
257   @Test
listNotificationChannelDescriptorsTest4()258   public void listNotificationChannelDescriptorsTest4() throws Exception {
259     NotificationChannelDescriptor responsesElement =
260         NotificationChannelDescriptor.newBuilder().build();
261     ListNotificationChannelDescriptorsResponse expectedResponse =
262         ListNotificationChannelDescriptorsResponse.newBuilder()
263             .setNextPageToken("")
264             .addAllChannelDescriptors(Arrays.asList(responsesElement))
265             .build();
266     mockNotificationChannelService.addResponse(expectedResponse);
267 
268     String name = "name3373707";
269 
270     ListNotificationChannelDescriptorsPagedResponse pagedListResponse =
271         client.listNotificationChannelDescriptors(name);
272 
273     List<NotificationChannelDescriptor> resources =
274         Lists.newArrayList(pagedListResponse.iterateAll());
275 
276     Assert.assertEquals(1, resources.size());
277     Assert.assertEquals(expectedResponse.getChannelDescriptorsList().get(0), resources.get(0));
278 
279     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
280     Assert.assertEquals(1, actualRequests.size());
281     ListNotificationChannelDescriptorsRequest actualRequest =
282         ((ListNotificationChannelDescriptorsRequest) actualRequests.get(0));
283 
284     Assert.assertEquals(name, actualRequest.getName());
285     Assert.assertTrue(
286         channelProvider.isHeaderSent(
287             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
288             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
289   }
290 
291   @Test
listNotificationChannelDescriptorsExceptionTest4()292   public void listNotificationChannelDescriptorsExceptionTest4() throws Exception {
293     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
294     mockNotificationChannelService.addException(exception);
295 
296     try {
297       String name = "name3373707";
298       client.listNotificationChannelDescriptors(name);
299       Assert.fail("No exception raised");
300     } catch (InvalidArgumentException e) {
301       // Expected exception.
302     }
303   }
304 
305   @Test
getNotificationChannelDescriptorTest()306   public void getNotificationChannelDescriptorTest() throws Exception {
307     NotificationChannelDescriptor expectedResponse =
308         NotificationChannelDescriptor.newBuilder()
309             .setName(
310                 NotificationChannelDescriptorName.ofProjectChannelDescriptorName(
311                         "[PROJECT]", "[CHANNEL_DESCRIPTOR]")
312                     .toString())
313             .setType("type3575610")
314             .setDisplayName("displayName1714148973")
315             .setDescription("description-1724546052")
316             .addAllLabels(new ArrayList<LabelDescriptor>())
317             .addAllSupportedTiers(new ArrayList<ServiceTier>())
318             .setLaunchStage(LaunchStage.forNumber(0))
319             .build();
320     mockNotificationChannelService.addResponse(expectedResponse);
321 
322     NotificationChannelDescriptorName name =
323         NotificationChannelDescriptorName.ofProjectChannelDescriptorName(
324             "[PROJECT]", "[CHANNEL_DESCRIPTOR]");
325 
326     NotificationChannelDescriptor actualResponse = client.getNotificationChannelDescriptor(name);
327     Assert.assertEquals(expectedResponse, actualResponse);
328 
329     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
330     Assert.assertEquals(1, actualRequests.size());
331     GetNotificationChannelDescriptorRequest actualRequest =
332         ((GetNotificationChannelDescriptorRequest) actualRequests.get(0));
333 
334     Assert.assertEquals(name.toString(), actualRequest.getName());
335     Assert.assertTrue(
336         channelProvider.isHeaderSent(
337             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
338             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
339   }
340 
341   @Test
getNotificationChannelDescriptorExceptionTest()342   public void getNotificationChannelDescriptorExceptionTest() throws Exception {
343     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
344     mockNotificationChannelService.addException(exception);
345 
346     try {
347       NotificationChannelDescriptorName name =
348           NotificationChannelDescriptorName.ofProjectChannelDescriptorName(
349               "[PROJECT]", "[CHANNEL_DESCRIPTOR]");
350       client.getNotificationChannelDescriptor(name);
351       Assert.fail("No exception raised");
352     } catch (InvalidArgumentException e) {
353       // Expected exception.
354     }
355   }
356 
357   @Test
getNotificationChannelDescriptorTest2()358   public void getNotificationChannelDescriptorTest2() throws Exception {
359     NotificationChannelDescriptor expectedResponse =
360         NotificationChannelDescriptor.newBuilder()
361             .setName(
362                 NotificationChannelDescriptorName.ofProjectChannelDescriptorName(
363                         "[PROJECT]", "[CHANNEL_DESCRIPTOR]")
364                     .toString())
365             .setType("type3575610")
366             .setDisplayName("displayName1714148973")
367             .setDescription("description-1724546052")
368             .addAllLabels(new ArrayList<LabelDescriptor>())
369             .addAllSupportedTiers(new ArrayList<ServiceTier>())
370             .setLaunchStage(LaunchStage.forNumber(0))
371             .build();
372     mockNotificationChannelService.addResponse(expectedResponse);
373 
374     String name = "name3373707";
375 
376     NotificationChannelDescriptor actualResponse = client.getNotificationChannelDescriptor(name);
377     Assert.assertEquals(expectedResponse, actualResponse);
378 
379     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
380     Assert.assertEquals(1, actualRequests.size());
381     GetNotificationChannelDescriptorRequest actualRequest =
382         ((GetNotificationChannelDescriptorRequest) actualRequests.get(0));
383 
384     Assert.assertEquals(name, actualRequest.getName());
385     Assert.assertTrue(
386         channelProvider.isHeaderSent(
387             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
388             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
389   }
390 
391   @Test
getNotificationChannelDescriptorExceptionTest2()392   public void getNotificationChannelDescriptorExceptionTest2() throws Exception {
393     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
394     mockNotificationChannelService.addException(exception);
395 
396     try {
397       String name = "name3373707";
398       client.getNotificationChannelDescriptor(name);
399       Assert.fail("No exception raised");
400     } catch (InvalidArgumentException e) {
401       // Expected exception.
402     }
403   }
404 
405   @Test
listNotificationChannelsTest()406   public void listNotificationChannelsTest() throws Exception {
407     NotificationChannel responsesElement = NotificationChannel.newBuilder().build();
408     ListNotificationChannelsResponse expectedResponse =
409         ListNotificationChannelsResponse.newBuilder()
410             .setNextPageToken("")
411             .addAllNotificationChannels(Arrays.asList(responsesElement))
412             .build();
413     mockNotificationChannelService.addResponse(expectedResponse);
414 
415     FolderName name = FolderName.of("[FOLDER]");
416 
417     ListNotificationChannelsPagedResponse pagedListResponse = client.listNotificationChannels(name);
418 
419     List<NotificationChannel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
420 
421     Assert.assertEquals(1, resources.size());
422     Assert.assertEquals(expectedResponse.getNotificationChannelsList().get(0), resources.get(0));
423 
424     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
425     Assert.assertEquals(1, actualRequests.size());
426     ListNotificationChannelsRequest actualRequest =
427         ((ListNotificationChannelsRequest) actualRequests.get(0));
428 
429     Assert.assertEquals(name.toString(), actualRequest.getName());
430     Assert.assertTrue(
431         channelProvider.isHeaderSent(
432             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
433             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
434   }
435 
436   @Test
listNotificationChannelsExceptionTest()437   public void listNotificationChannelsExceptionTest() throws Exception {
438     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
439     mockNotificationChannelService.addException(exception);
440 
441     try {
442       FolderName name = FolderName.of("[FOLDER]");
443       client.listNotificationChannels(name);
444       Assert.fail("No exception raised");
445     } catch (InvalidArgumentException e) {
446       // Expected exception.
447     }
448   }
449 
450   @Test
listNotificationChannelsTest2()451   public void listNotificationChannelsTest2() throws Exception {
452     NotificationChannel responsesElement = NotificationChannel.newBuilder().build();
453     ListNotificationChannelsResponse expectedResponse =
454         ListNotificationChannelsResponse.newBuilder()
455             .setNextPageToken("")
456             .addAllNotificationChannels(Arrays.asList(responsesElement))
457             .build();
458     mockNotificationChannelService.addResponse(expectedResponse);
459 
460     OrganizationName name = OrganizationName.of("[ORGANIZATION]");
461 
462     ListNotificationChannelsPagedResponse pagedListResponse = client.listNotificationChannels(name);
463 
464     List<NotificationChannel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
465 
466     Assert.assertEquals(1, resources.size());
467     Assert.assertEquals(expectedResponse.getNotificationChannelsList().get(0), resources.get(0));
468 
469     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
470     Assert.assertEquals(1, actualRequests.size());
471     ListNotificationChannelsRequest actualRequest =
472         ((ListNotificationChannelsRequest) actualRequests.get(0));
473 
474     Assert.assertEquals(name.toString(), actualRequest.getName());
475     Assert.assertTrue(
476         channelProvider.isHeaderSent(
477             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
478             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
479   }
480 
481   @Test
listNotificationChannelsExceptionTest2()482   public void listNotificationChannelsExceptionTest2() throws Exception {
483     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
484     mockNotificationChannelService.addException(exception);
485 
486     try {
487       OrganizationName name = OrganizationName.of("[ORGANIZATION]");
488       client.listNotificationChannels(name);
489       Assert.fail("No exception raised");
490     } catch (InvalidArgumentException e) {
491       // Expected exception.
492     }
493   }
494 
495   @Test
listNotificationChannelsTest3()496   public void listNotificationChannelsTest3() throws Exception {
497     NotificationChannel responsesElement = NotificationChannel.newBuilder().build();
498     ListNotificationChannelsResponse expectedResponse =
499         ListNotificationChannelsResponse.newBuilder()
500             .setNextPageToken("")
501             .addAllNotificationChannels(Arrays.asList(responsesElement))
502             .build();
503     mockNotificationChannelService.addResponse(expectedResponse);
504 
505     ProjectName name = ProjectName.of("[PROJECT]");
506 
507     ListNotificationChannelsPagedResponse pagedListResponse = client.listNotificationChannels(name);
508 
509     List<NotificationChannel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
510 
511     Assert.assertEquals(1, resources.size());
512     Assert.assertEquals(expectedResponse.getNotificationChannelsList().get(0), resources.get(0));
513 
514     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
515     Assert.assertEquals(1, actualRequests.size());
516     ListNotificationChannelsRequest actualRequest =
517         ((ListNotificationChannelsRequest) actualRequests.get(0));
518 
519     Assert.assertEquals(name.toString(), actualRequest.getName());
520     Assert.assertTrue(
521         channelProvider.isHeaderSent(
522             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
523             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
524   }
525 
526   @Test
listNotificationChannelsExceptionTest3()527   public void listNotificationChannelsExceptionTest3() throws Exception {
528     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
529     mockNotificationChannelService.addException(exception);
530 
531     try {
532       ProjectName name = ProjectName.of("[PROJECT]");
533       client.listNotificationChannels(name);
534       Assert.fail("No exception raised");
535     } catch (InvalidArgumentException e) {
536       // Expected exception.
537     }
538   }
539 
540   @Test
listNotificationChannelsTest4()541   public void listNotificationChannelsTest4() throws Exception {
542     NotificationChannel responsesElement = NotificationChannel.newBuilder().build();
543     ListNotificationChannelsResponse expectedResponse =
544         ListNotificationChannelsResponse.newBuilder()
545             .setNextPageToken("")
546             .addAllNotificationChannels(Arrays.asList(responsesElement))
547             .build();
548     mockNotificationChannelService.addResponse(expectedResponse);
549 
550     String name = "name3373707";
551 
552     ListNotificationChannelsPagedResponse pagedListResponse = client.listNotificationChannels(name);
553 
554     List<NotificationChannel> resources = Lists.newArrayList(pagedListResponse.iterateAll());
555 
556     Assert.assertEquals(1, resources.size());
557     Assert.assertEquals(expectedResponse.getNotificationChannelsList().get(0), resources.get(0));
558 
559     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
560     Assert.assertEquals(1, actualRequests.size());
561     ListNotificationChannelsRequest actualRequest =
562         ((ListNotificationChannelsRequest) actualRequests.get(0));
563 
564     Assert.assertEquals(name, actualRequest.getName());
565     Assert.assertTrue(
566         channelProvider.isHeaderSent(
567             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
568             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
569   }
570 
571   @Test
listNotificationChannelsExceptionTest4()572   public void listNotificationChannelsExceptionTest4() throws Exception {
573     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
574     mockNotificationChannelService.addException(exception);
575 
576     try {
577       String name = "name3373707";
578       client.listNotificationChannels(name);
579       Assert.fail("No exception raised");
580     } catch (InvalidArgumentException e) {
581       // Expected exception.
582     }
583   }
584 
585   @Test
getNotificationChannelTest()586   public void getNotificationChannelTest() throws Exception {
587     NotificationChannel expectedResponse =
588         NotificationChannel.newBuilder()
589             .setType("type3575610")
590             .setName(
591                 NotificationChannelName.ofProjectNotificationChannelName(
592                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
593                     .toString())
594             .setDisplayName("displayName1714148973")
595             .setDescription("description-1724546052")
596             .putAllLabels(new HashMap<String, String>())
597             .putAllUserLabels(new HashMap<String, String>())
598             .setEnabled(BoolValue.newBuilder().build())
599             .setCreationRecord(MutationRecord.newBuilder().build())
600             .addAllMutationRecords(new ArrayList<MutationRecord>())
601             .build();
602     mockNotificationChannelService.addResponse(expectedResponse);
603 
604     NotificationChannelName name =
605         NotificationChannelName.ofProjectNotificationChannelName(
606             "[PROJECT]", "[NOTIFICATION_CHANNEL]");
607 
608     NotificationChannel actualResponse = client.getNotificationChannel(name);
609     Assert.assertEquals(expectedResponse, actualResponse);
610 
611     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
612     Assert.assertEquals(1, actualRequests.size());
613     GetNotificationChannelRequest actualRequest =
614         ((GetNotificationChannelRequest) actualRequests.get(0));
615 
616     Assert.assertEquals(name.toString(), actualRequest.getName());
617     Assert.assertTrue(
618         channelProvider.isHeaderSent(
619             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
620             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
621   }
622 
623   @Test
getNotificationChannelExceptionTest()624   public void getNotificationChannelExceptionTest() throws Exception {
625     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
626     mockNotificationChannelService.addException(exception);
627 
628     try {
629       NotificationChannelName name =
630           NotificationChannelName.ofProjectNotificationChannelName(
631               "[PROJECT]", "[NOTIFICATION_CHANNEL]");
632       client.getNotificationChannel(name);
633       Assert.fail("No exception raised");
634     } catch (InvalidArgumentException e) {
635       // Expected exception.
636     }
637   }
638 
639   @Test
getNotificationChannelTest2()640   public void getNotificationChannelTest2() throws Exception {
641     NotificationChannel expectedResponse =
642         NotificationChannel.newBuilder()
643             .setType("type3575610")
644             .setName(
645                 NotificationChannelName.ofProjectNotificationChannelName(
646                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
647                     .toString())
648             .setDisplayName("displayName1714148973")
649             .setDescription("description-1724546052")
650             .putAllLabels(new HashMap<String, String>())
651             .putAllUserLabels(new HashMap<String, String>())
652             .setEnabled(BoolValue.newBuilder().build())
653             .setCreationRecord(MutationRecord.newBuilder().build())
654             .addAllMutationRecords(new ArrayList<MutationRecord>())
655             .build();
656     mockNotificationChannelService.addResponse(expectedResponse);
657 
658     String name = "name3373707";
659 
660     NotificationChannel actualResponse = client.getNotificationChannel(name);
661     Assert.assertEquals(expectedResponse, actualResponse);
662 
663     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
664     Assert.assertEquals(1, actualRequests.size());
665     GetNotificationChannelRequest actualRequest =
666         ((GetNotificationChannelRequest) actualRequests.get(0));
667 
668     Assert.assertEquals(name, actualRequest.getName());
669     Assert.assertTrue(
670         channelProvider.isHeaderSent(
671             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
672             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
673   }
674 
675   @Test
getNotificationChannelExceptionTest2()676   public void getNotificationChannelExceptionTest2() throws Exception {
677     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
678     mockNotificationChannelService.addException(exception);
679 
680     try {
681       String name = "name3373707";
682       client.getNotificationChannel(name);
683       Assert.fail("No exception raised");
684     } catch (InvalidArgumentException e) {
685       // Expected exception.
686     }
687   }
688 
689   @Test
createNotificationChannelTest()690   public void createNotificationChannelTest() throws Exception {
691     NotificationChannel expectedResponse =
692         NotificationChannel.newBuilder()
693             .setType("type3575610")
694             .setName(
695                 NotificationChannelName.ofProjectNotificationChannelName(
696                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
697                     .toString())
698             .setDisplayName("displayName1714148973")
699             .setDescription("description-1724546052")
700             .putAllLabels(new HashMap<String, String>())
701             .putAllUserLabels(new HashMap<String, String>())
702             .setEnabled(BoolValue.newBuilder().build())
703             .setCreationRecord(MutationRecord.newBuilder().build())
704             .addAllMutationRecords(new ArrayList<MutationRecord>())
705             .build();
706     mockNotificationChannelService.addResponse(expectedResponse);
707 
708     FolderName name = FolderName.of("[FOLDER]");
709     NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
710 
711     NotificationChannel actualResponse =
712         client.createNotificationChannel(name, notificationChannel);
713     Assert.assertEquals(expectedResponse, actualResponse);
714 
715     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
716     Assert.assertEquals(1, actualRequests.size());
717     CreateNotificationChannelRequest actualRequest =
718         ((CreateNotificationChannelRequest) actualRequests.get(0));
719 
720     Assert.assertEquals(name.toString(), actualRequest.getName());
721     Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
722     Assert.assertTrue(
723         channelProvider.isHeaderSent(
724             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
725             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
726   }
727 
728   @Test
createNotificationChannelExceptionTest()729   public void createNotificationChannelExceptionTest() throws Exception {
730     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
731     mockNotificationChannelService.addException(exception);
732 
733     try {
734       FolderName name = FolderName.of("[FOLDER]");
735       NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
736       client.createNotificationChannel(name, notificationChannel);
737       Assert.fail("No exception raised");
738     } catch (InvalidArgumentException e) {
739       // Expected exception.
740     }
741   }
742 
743   @Test
createNotificationChannelTest2()744   public void createNotificationChannelTest2() throws Exception {
745     NotificationChannel expectedResponse =
746         NotificationChannel.newBuilder()
747             .setType("type3575610")
748             .setName(
749                 NotificationChannelName.ofProjectNotificationChannelName(
750                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
751                     .toString())
752             .setDisplayName("displayName1714148973")
753             .setDescription("description-1724546052")
754             .putAllLabels(new HashMap<String, String>())
755             .putAllUserLabels(new HashMap<String, String>())
756             .setEnabled(BoolValue.newBuilder().build())
757             .setCreationRecord(MutationRecord.newBuilder().build())
758             .addAllMutationRecords(new ArrayList<MutationRecord>())
759             .build();
760     mockNotificationChannelService.addResponse(expectedResponse);
761 
762     OrganizationName name = OrganizationName.of("[ORGANIZATION]");
763     NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
764 
765     NotificationChannel actualResponse =
766         client.createNotificationChannel(name, notificationChannel);
767     Assert.assertEquals(expectedResponse, actualResponse);
768 
769     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
770     Assert.assertEquals(1, actualRequests.size());
771     CreateNotificationChannelRequest actualRequest =
772         ((CreateNotificationChannelRequest) actualRequests.get(0));
773 
774     Assert.assertEquals(name.toString(), actualRequest.getName());
775     Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
776     Assert.assertTrue(
777         channelProvider.isHeaderSent(
778             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
779             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
780   }
781 
782   @Test
createNotificationChannelExceptionTest2()783   public void createNotificationChannelExceptionTest2() throws Exception {
784     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
785     mockNotificationChannelService.addException(exception);
786 
787     try {
788       OrganizationName name = OrganizationName.of("[ORGANIZATION]");
789       NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
790       client.createNotificationChannel(name, notificationChannel);
791       Assert.fail("No exception raised");
792     } catch (InvalidArgumentException e) {
793       // Expected exception.
794     }
795   }
796 
797   @Test
createNotificationChannelTest3()798   public void createNotificationChannelTest3() throws Exception {
799     NotificationChannel expectedResponse =
800         NotificationChannel.newBuilder()
801             .setType("type3575610")
802             .setName(
803                 NotificationChannelName.ofProjectNotificationChannelName(
804                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
805                     .toString())
806             .setDisplayName("displayName1714148973")
807             .setDescription("description-1724546052")
808             .putAllLabels(new HashMap<String, String>())
809             .putAllUserLabels(new HashMap<String, String>())
810             .setEnabled(BoolValue.newBuilder().build())
811             .setCreationRecord(MutationRecord.newBuilder().build())
812             .addAllMutationRecords(new ArrayList<MutationRecord>())
813             .build();
814     mockNotificationChannelService.addResponse(expectedResponse);
815 
816     ProjectName name = ProjectName.of("[PROJECT]");
817     NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
818 
819     NotificationChannel actualResponse =
820         client.createNotificationChannel(name, notificationChannel);
821     Assert.assertEquals(expectedResponse, actualResponse);
822 
823     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
824     Assert.assertEquals(1, actualRequests.size());
825     CreateNotificationChannelRequest actualRequest =
826         ((CreateNotificationChannelRequest) actualRequests.get(0));
827 
828     Assert.assertEquals(name.toString(), actualRequest.getName());
829     Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
830     Assert.assertTrue(
831         channelProvider.isHeaderSent(
832             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
833             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
834   }
835 
836   @Test
createNotificationChannelExceptionTest3()837   public void createNotificationChannelExceptionTest3() throws Exception {
838     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
839     mockNotificationChannelService.addException(exception);
840 
841     try {
842       ProjectName name = ProjectName.of("[PROJECT]");
843       NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
844       client.createNotificationChannel(name, notificationChannel);
845       Assert.fail("No exception raised");
846     } catch (InvalidArgumentException e) {
847       // Expected exception.
848     }
849   }
850 
851   @Test
createNotificationChannelTest4()852   public void createNotificationChannelTest4() throws Exception {
853     NotificationChannel expectedResponse =
854         NotificationChannel.newBuilder()
855             .setType("type3575610")
856             .setName(
857                 NotificationChannelName.ofProjectNotificationChannelName(
858                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
859                     .toString())
860             .setDisplayName("displayName1714148973")
861             .setDescription("description-1724546052")
862             .putAllLabels(new HashMap<String, String>())
863             .putAllUserLabels(new HashMap<String, String>())
864             .setEnabled(BoolValue.newBuilder().build())
865             .setCreationRecord(MutationRecord.newBuilder().build())
866             .addAllMutationRecords(new ArrayList<MutationRecord>())
867             .build();
868     mockNotificationChannelService.addResponse(expectedResponse);
869 
870     String name = "name3373707";
871     NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
872 
873     NotificationChannel actualResponse =
874         client.createNotificationChannel(name, notificationChannel);
875     Assert.assertEquals(expectedResponse, actualResponse);
876 
877     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
878     Assert.assertEquals(1, actualRequests.size());
879     CreateNotificationChannelRequest actualRequest =
880         ((CreateNotificationChannelRequest) actualRequests.get(0));
881 
882     Assert.assertEquals(name, actualRequest.getName());
883     Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
884     Assert.assertTrue(
885         channelProvider.isHeaderSent(
886             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
887             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
888   }
889 
890   @Test
createNotificationChannelExceptionTest4()891   public void createNotificationChannelExceptionTest4() throws Exception {
892     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
893     mockNotificationChannelService.addException(exception);
894 
895     try {
896       String name = "name3373707";
897       NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
898       client.createNotificationChannel(name, notificationChannel);
899       Assert.fail("No exception raised");
900     } catch (InvalidArgumentException e) {
901       // Expected exception.
902     }
903   }
904 
905   @Test
updateNotificationChannelTest()906   public void updateNotificationChannelTest() throws Exception {
907     NotificationChannel expectedResponse =
908         NotificationChannel.newBuilder()
909             .setType("type3575610")
910             .setName(
911                 NotificationChannelName.ofProjectNotificationChannelName(
912                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
913                     .toString())
914             .setDisplayName("displayName1714148973")
915             .setDescription("description-1724546052")
916             .putAllLabels(new HashMap<String, String>())
917             .putAllUserLabels(new HashMap<String, String>())
918             .setEnabled(BoolValue.newBuilder().build())
919             .setCreationRecord(MutationRecord.newBuilder().build())
920             .addAllMutationRecords(new ArrayList<MutationRecord>())
921             .build();
922     mockNotificationChannelService.addResponse(expectedResponse);
923 
924     FieldMask updateMask = FieldMask.newBuilder().build();
925     NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
926 
927     NotificationChannel actualResponse =
928         client.updateNotificationChannel(updateMask, notificationChannel);
929     Assert.assertEquals(expectedResponse, actualResponse);
930 
931     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
932     Assert.assertEquals(1, actualRequests.size());
933     UpdateNotificationChannelRequest actualRequest =
934         ((UpdateNotificationChannelRequest) actualRequests.get(0));
935 
936     Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
937     Assert.assertEquals(notificationChannel, actualRequest.getNotificationChannel());
938     Assert.assertTrue(
939         channelProvider.isHeaderSent(
940             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
941             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
942   }
943 
944   @Test
updateNotificationChannelExceptionTest()945   public void updateNotificationChannelExceptionTest() throws Exception {
946     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
947     mockNotificationChannelService.addException(exception);
948 
949     try {
950       FieldMask updateMask = FieldMask.newBuilder().build();
951       NotificationChannel notificationChannel = NotificationChannel.newBuilder().build();
952       client.updateNotificationChannel(updateMask, notificationChannel);
953       Assert.fail("No exception raised");
954     } catch (InvalidArgumentException e) {
955       // Expected exception.
956     }
957   }
958 
959   @Test
deleteNotificationChannelTest()960   public void deleteNotificationChannelTest() throws Exception {
961     Empty expectedResponse = Empty.newBuilder().build();
962     mockNotificationChannelService.addResponse(expectedResponse);
963 
964     NotificationChannelName name =
965         NotificationChannelName.ofProjectNotificationChannelName(
966             "[PROJECT]", "[NOTIFICATION_CHANNEL]");
967     boolean force = true;
968 
969     client.deleteNotificationChannel(name, force);
970 
971     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
972     Assert.assertEquals(1, actualRequests.size());
973     DeleteNotificationChannelRequest actualRequest =
974         ((DeleteNotificationChannelRequest) actualRequests.get(0));
975 
976     Assert.assertEquals(name.toString(), actualRequest.getName());
977     Assert.assertEquals(force, actualRequest.getForce());
978     Assert.assertTrue(
979         channelProvider.isHeaderSent(
980             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
981             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
982   }
983 
984   @Test
deleteNotificationChannelExceptionTest()985   public void deleteNotificationChannelExceptionTest() throws Exception {
986     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
987     mockNotificationChannelService.addException(exception);
988 
989     try {
990       NotificationChannelName name =
991           NotificationChannelName.ofProjectNotificationChannelName(
992               "[PROJECT]", "[NOTIFICATION_CHANNEL]");
993       boolean force = true;
994       client.deleteNotificationChannel(name, force);
995       Assert.fail("No exception raised");
996     } catch (InvalidArgumentException e) {
997       // Expected exception.
998     }
999   }
1000 
1001   @Test
deleteNotificationChannelTest2()1002   public void deleteNotificationChannelTest2() throws Exception {
1003     Empty expectedResponse = Empty.newBuilder().build();
1004     mockNotificationChannelService.addResponse(expectedResponse);
1005 
1006     String name = "name3373707";
1007     boolean force = true;
1008 
1009     client.deleteNotificationChannel(name, force);
1010 
1011     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1012     Assert.assertEquals(1, actualRequests.size());
1013     DeleteNotificationChannelRequest actualRequest =
1014         ((DeleteNotificationChannelRequest) actualRequests.get(0));
1015 
1016     Assert.assertEquals(name, actualRequest.getName());
1017     Assert.assertEquals(force, actualRequest.getForce());
1018     Assert.assertTrue(
1019         channelProvider.isHeaderSent(
1020             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1021             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1022   }
1023 
1024   @Test
deleteNotificationChannelExceptionTest2()1025   public void deleteNotificationChannelExceptionTest2() throws Exception {
1026     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1027     mockNotificationChannelService.addException(exception);
1028 
1029     try {
1030       String name = "name3373707";
1031       boolean force = true;
1032       client.deleteNotificationChannel(name, force);
1033       Assert.fail("No exception raised");
1034     } catch (InvalidArgumentException e) {
1035       // Expected exception.
1036     }
1037   }
1038 
1039   @Test
sendNotificationChannelVerificationCodeTest()1040   public void sendNotificationChannelVerificationCodeTest() throws Exception {
1041     Empty expectedResponse = Empty.newBuilder().build();
1042     mockNotificationChannelService.addResponse(expectedResponse);
1043 
1044     NotificationChannelName name =
1045         NotificationChannelName.ofProjectNotificationChannelName(
1046             "[PROJECT]", "[NOTIFICATION_CHANNEL]");
1047 
1048     client.sendNotificationChannelVerificationCode(name);
1049 
1050     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1051     Assert.assertEquals(1, actualRequests.size());
1052     SendNotificationChannelVerificationCodeRequest actualRequest =
1053         ((SendNotificationChannelVerificationCodeRequest) actualRequests.get(0));
1054 
1055     Assert.assertEquals(name.toString(), actualRequest.getName());
1056     Assert.assertTrue(
1057         channelProvider.isHeaderSent(
1058             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1059             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1060   }
1061 
1062   @Test
sendNotificationChannelVerificationCodeExceptionTest()1063   public void sendNotificationChannelVerificationCodeExceptionTest() throws Exception {
1064     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1065     mockNotificationChannelService.addException(exception);
1066 
1067     try {
1068       NotificationChannelName name =
1069           NotificationChannelName.ofProjectNotificationChannelName(
1070               "[PROJECT]", "[NOTIFICATION_CHANNEL]");
1071       client.sendNotificationChannelVerificationCode(name);
1072       Assert.fail("No exception raised");
1073     } catch (InvalidArgumentException e) {
1074       // Expected exception.
1075     }
1076   }
1077 
1078   @Test
sendNotificationChannelVerificationCodeTest2()1079   public void sendNotificationChannelVerificationCodeTest2() throws Exception {
1080     Empty expectedResponse = Empty.newBuilder().build();
1081     mockNotificationChannelService.addResponse(expectedResponse);
1082 
1083     String name = "name3373707";
1084 
1085     client.sendNotificationChannelVerificationCode(name);
1086 
1087     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1088     Assert.assertEquals(1, actualRequests.size());
1089     SendNotificationChannelVerificationCodeRequest actualRequest =
1090         ((SendNotificationChannelVerificationCodeRequest) actualRequests.get(0));
1091 
1092     Assert.assertEquals(name, actualRequest.getName());
1093     Assert.assertTrue(
1094         channelProvider.isHeaderSent(
1095             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1096             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1097   }
1098 
1099   @Test
sendNotificationChannelVerificationCodeExceptionTest2()1100   public void sendNotificationChannelVerificationCodeExceptionTest2() throws Exception {
1101     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1102     mockNotificationChannelService.addException(exception);
1103 
1104     try {
1105       String name = "name3373707";
1106       client.sendNotificationChannelVerificationCode(name);
1107       Assert.fail("No exception raised");
1108     } catch (InvalidArgumentException e) {
1109       // Expected exception.
1110     }
1111   }
1112 
1113   @Test
getNotificationChannelVerificationCodeTest()1114   public void getNotificationChannelVerificationCodeTest() throws Exception {
1115     GetNotificationChannelVerificationCodeResponse expectedResponse =
1116         GetNotificationChannelVerificationCodeResponse.newBuilder()
1117             .setCode("code3059181")
1118             .setExpireTime(Timestamp.newBuilder().build())
1119             .build();
1120     mockNotificationChannelService.addResponse(expectedResponse);
1121 
1122     NotificationChannelName name =
1123         NotificationChannelName.ofProjectNotificationChannelName(
1124             "[PROJECT]", "[NOTIFICATION_CHANNEL]");
1125 
1126     GetNotificationChannelVerificationCodeResponse actualResponse =
1127         client.getNotificationChannelVerificationCode(name);
1128     Assert.assertEquals(expectedResponse, actualResponse);
1129 
1130     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1131     Assert.assertEquals(1, actualRequests.size());
1132     GetNotificationChannelVerificationCodeRequest actualRequest =
1133         ((GetNotificationChannelVerificationCodeRequest) actualRequests.get(0));
1134 
1135     Assert.assertEquals(name.toString(), actualRequest.getName());
1136     Assert.assertTrue(
1137         channelProvider.isHeaderSent(
1138             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1139             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1140   }
1141 
1142   @Test
getNotificationChannelVerificationCodeExceptionTest()1143   public void getNotificationChannelVerificationCodeExceptionTest() throws Exception {
1144     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1145     mockNotificationChannelService.addException(exception);
1146 
1147     try {
1148       NotificationChannelName name =
1149           NotificationChannelName.ofProjectNotificationChannelName(
1150               "[PROJECT]", "[NOTIFICATION_CHANNEL]");
1151       client.getNotificationChannelVerificationCode(name);
1152       Assert.fail("No exception raised");
1153     } catch (InvalidArgumentException e) {
1154       // Expected exception.
1155     }
1156   }
1157 
1158   @Test
getNotificationChannelVerificationCodeTest2()1159   public void getNotificationChannelVerificationCodeTest2() throws Exception {
1160     GetNotificationChannelVerificationCodeResponse expectedResponse =
1161         GetNotificationChannelVerificationCodeResponse.newBuilder()
1162             .setCode("code3059181")
1163             .setExpireTime(Timestamp.newBuilder().build())
1164             .build();
1165     mockNotificationChannelService.addResponse(expectedResponse);
1166 
1167     String name = "name3373707";
1168 
1169     GetNotificationChannelVerificationCodeResponse actualResponse =
1170         client.getNotificationChannelVerificationCode(name);
1171     Assert.assertEquals(expectedResponse, actualResponse);
1172 
1173     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1174     Assert.assertEquals(1, actualRequests.size());
1175     GetNotificationChannelVerificationCodeRequest actualRequest =
1176         ((GetNotificationChannelVerificationCodeRequest) actualRequests.get(0));
1177 
1178     Assert.assertEquals(name, actualRequest.getName());
1179     Assert.assertTrue(
1180         channelProvider.isHeaderSent(
1181             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1182             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1183   }
1184 
1185   @Test
getNotificationChannelVerificationCodeExceptionTest2()1186   public void getNotificationChannelVerificationCodeExceptionTest2() throws Exception {
1187     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1188     mockNotificationChannelService.addException(exception);
1189 
1190     try {
1191       String name = "name3373707";
1192       client.getNotificationChannelVerificationCode(name);
1193       Assert.fail("No exception raised");
1194     } catch (InvalidArgumentException e) {
1195       // Expected exception.
1196     }
1197   }
1198 
1199   @Test
verifyNotificationChannelTest()1200   public void verifyNotificationChannelTest() throws Exception {
1201     NotificationChannel expectedResponse =
1202         NotificationChannel.newBuilder()
1203             .setType("type3575610")
1204             .setName(
1205                 NotificationChannelName.ofProjectNotificationChannelName(
1206                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
1207                     .toString())
1208             .setDisplayName("displayName1714148973")
1209             .setDescription("description-1724546052")
1210             .putAllLabels(new HashMap<String, String>())
1211             .putAllUserLabels(new HashMap<String, String>())
1212             .setEnabled(BoolValue.newBuilder().build())
1213             .setCreationRecord(MutationRecord.newBuilder().build())
1214             .addAllMutationRecords(new ArrayList<MutationRecord>())
1215             .build();
1216     mockNotificationChannelService.addResponse(expectedResponse);
1217 
1218     NotificationChannelName name =
1219         NotificationChannelName.ofProjectNotificationChannelName(
1220             "[PROJECT]", "[NOTIFICATION_CHANNEL]");
1221     String code = "code3059181";
1222 
1223     NotificationChannel actualResponse = client.verifyNotificationChannel(name, code);
1224     Assert.assertEquals(expectedResponse, actualResponse);
1225 
1226     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1227     Assert.assertEquals(1, actualRequests.size());
1228     VerifyNotificationChannelRequest actualRequest =
1229         ((VerifyNotificationChannelRequest) actualRequests.get(0));
1230 
1231     Assert.assertEquals(name.toString(), actualRequest.getName());
1232     Assert.assertEquals(code, actualRequest.getCode());
1233     Assert.assertTrue(
1234         channelProvider.isHeaderSent(
1235             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1236             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1237   }
1238 
1239   @Test
verifyNotificationChannelExceptionTest()1240   public void verifyNotificationChannelExceptionTest() throws Exception {
1241     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1242     mockNotificationChannelService.addException(exception);
1243 
1244     try {
1245       NotificationChannelName name =
1246           NotificationChannelName.ofProjectNotificationChannelName(
1247               "[PROJECT]", "[NOTIFICATION_CHANNEL]");
1248       String code = "code3059181";
1249       client.verifyNotificationChannel(name, code);
1250       Assert.fail("No exception raised");
1251     } catch (InvalidArgumentException e) {
1252       // Expected exception.
1253     }
1254   }
1255 
1256   @Test
verifyNotificationChannelTest2()1257   public void verifyNotificationChannelTest2() throws Exception {
1258     NotificationChannel expectedResponse =
1259         NotificationChannel.newBuilder()
1260             .setType("type3575610")
1261             .setName(
1262                 NotificationChannelName.ofProjectNotificationChannelName(
1263                         "[PROJECT]", "[NOTIFICATION_CHANNEL]")
1264                     .toString())
1265             .setDisplayName("displayName1714148973")
1266             .setDescription("description-1724546052")
1267             .putAllLabels(new HashMap<String, String>())
1268             .putAllUserLabels(new HashMap<String, String>())
1269             .setEnabled(BoolValue.newBuilder().build())
1270             .setCreationRecord(MutationRecord.newBuilder().build())
1271             .addAllMutationRecords(new ArrayList<MutationRecord>())
1272             .build();
1273     mockNotificationChannelService.addResponse(expectedResponse);
1274 
1275     String name = "name3373707";
1276     String code = "code3059181";
1277 
1278     NotificationChannel actualResponse = client.verifyNotificationChannel(name, code);
1279     Assert.assertEquals(expectedResponse, actualResponse);
1280 
1281     List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
1282     Assert.assertEquals(1, actualRequests.size());
1283     VerifyNotificationChannelRequest actualRequest =
1284         ((VerifyNotificationChannelRequest) actualRequests.get(0));
1285 
1286     Assert.assertEquals(name, actualRequest.getName());
1287     Assert.assertEquals(code, actualRequest.getCode());
1288     Assert.assertTrue(
1289         channelProvider.isHeaderSent(
1290             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1291             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1292   }
1293 
1294   @Test
verifyNotificationChannelExceptionTest2()1295   public void verifyNotificationChannelExceptionTest2() throws Exception {
1296     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1297     mockNotificationChannelService.addException(exception);
1298 
1299     try {
1300       String name = "name3373707";
1301       String code = "code3059181";
1302       client.verifyNotificationChannel(name, code);
1303       Assert.fail("No exception raised");
1304     } catch (InvalidArgumentException e) {
1305       // Expected exception.
1306     }
1307   }
1308 }
1309