• 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.iot.v1;
18 
19 import static com.google.cloud.iot.v1.DeviceManagerClient.ListDeviceRegistriesPagedResponse;
20 import static com.google.cloud.iot.v1.DeviceManagerClient.ListDevicesPagedResponse;
21 
22 import com.google.api.gax.core.NoCredentialsProvider;
23 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
24 import com.google.api.gax.httpjson.testing.MockHttpService;
25 import com.google.api.gax.rpc.ApiClientHeaderProvider;
26 import com.google.api.gax.rpc.ApiException;
27 import com.google.api.gax.rpc.ApiExceptionFactory;
28 import com.google.api.gax.rpc.InvalidArgumentException;
29 import com.google.api.gax.rpc.StatusCode;
30 import com.google.api.gax.rpc.testing.FakeStatusCode;
31 import com.google.api.resourcenames.ResourceName;
32 import com.google.cloud.iot.v1.stub.HttpJsonDeviceManagerStub;
33 import com.google.common.collect.Lists;
34 import com.google.iam.v1.AuditConfig;
35 import com.google.iam.v1.Binding;
36 import com.google.iam.v1.Policy;
37 import com.google.iam.v1.TestIamPermissionsResponse;
38 import com.google.protobuf.ByteString;
39 import com.google.protobuf.Empty;
40 import com.google.protobuf.FieldMask;
41 import com.google.protobuf.Timestamp;
42 import com.google.rpc.Status;
43 import java.io.IOException;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.HashMap;
47 import java.util.List;
48 import javax.annotation.Generated;
49 import org.junit.After;
50 import org.junit.AfterClass;
51 import org.junit.Assert;
52 import org.junit.Before;
53 import org.junit.BeforeClass;
54 import org.junit.Test;
55 
56 @Generated("by gapic-generator-java")
57 public class DeviceManagerClientHttpJsonTest {
58   private static MockHttpService mockService;
59   private static DeviceManagerClient client;
60 
61   @BeforeClass
startStaticServer()62   public static void startStaticServer() throws IOException {
63     mockService =
64         new MockHttpService(
65             HttpJsonDeviceManagerStub.getMethodDescriptors(),
66             DeviceManagerSettings.getDefaultEndpoint());
67     DeviceManagerSettings settings =
68         DeviceManagerSettings.newHttpJsonBuilder()
69             .setTransportChannelProvider(
70                 DeviceManagerSettings.defaultHttpJsonTransportProviderBuilder()
71                     .setHttpTransport(mockService)
72                     .build())
73             .setCredentialsProvider(NoCredentialsProvider.create())
74             .build();
75     client = DeviceManagerClient.create(settings);
76   }
77 
78   @AfterClass
stopServer()79   public static void stopServer() {
80     client.close();
81   }
82 
83   @Before
setUp()84   public void setUp() {}
85 
86   @After
tearDown()87   public void tearDown() throws Exception {
88     mockService.reset();
89   }
90 
91   @Test
createDeviceRegistryTest()92   public void createDeviceRegistryTest() throws Exception {
93     DeviceRegistry expectedResponse =
94         DeviceRegistry.newBuilder()
95             .setId("id3355")
96             .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
97             .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
98             .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
99             .setMqttConfig(MqttConfig.newBuilder().build())
100             .setHttpConfig(HttpConfig.newBuilder().build())
101             .setLogLevel(LogLevel.forNumber(0))
102             .addAllCredentials(new ArrayList<RegistryCredential>())
103             .build();
104     mockService.addResponse(expectedResponse);
105 
106     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
107     DeviceRegistry deviceRegistry = DeviceRegistry.newBuilder().build();
108 
109     DeviceRegistry actualResponse = client.createDeviceRegistry(parent, deviceRegistry);
110     Assert.assertEquals(expectedResponse, actualResponse);
111 
112     List<String> actualRequests = mockService.getRequestPaths();
113     Assert.assertEquals(1, actualRequests.size());
114 
115     String apiClientHeaderKey =
116         mockService
117             .getRequestHeaders()
118             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
119             .iterator()
120             .next();
121     Assert.assertTrue(
122         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
123             .matcher(apiClientHeaderKey)
124             .matches());
125   }
126 
127   @Test
createDeviceRegistryExceptionTest()128   public void createDeviceRegistryExceptionTest() throws Exception {
129     ApiException exception =
130         ApiExceptionFactory.createException(
131             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
132     mockService.addException(exception);
133 
134     try {
135       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
136       DeviceRegistry deviceRegistry = DeviceRegistry.newBuilder().build();
137       client.createDeviceRegistry(parent, deviceRegistry);
138       Assert.fail("No exception raised");
139     } catch (InvalidArgumentException e) {
140       // Expected exception.
141     }
142   }
143 
144   @Test
createDeviceRegistryTest2()145   public void createDeviceRegistryTest2() throws Exception {
146     DeviceRegistry expectedResponse =
147         DeviceRegistry.newBuilder()
148             .setId("id3355")
149             .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
150             .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
151             .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
152             .setMqttConfig(MqttConfig.newBuilder().build())
153             .setHttpConfig(HttpConfig.newBuilder().build())
154             .setLogLevel(LogLevel.forNumber(0))
155             .addAllCredentials(new ArrayList<RegistryCredential>())
156             .build();
157     mockService.addResponse(expectedResponse);
158 
159     String parent = "projects/project-5833/locations/location-5833";
160     DeviceRegistry deviceRegistry = DeviceRegistry.newBuilder().build();
161 
162     DeviceRegistry actualResponse = client.createDeviceRegistry(parent, deviceRegistry);
163     Assert.assertEquals(expectedResponse, actualResponse);
164 
165     List<String> actualRequests = mockService.getRequestPaths();
166     Assert.assertEquals(1, actualRequests.size());
167 
168     String apiClientHeaderKey =
169         mockService
170             .getRequestHeaders()
171             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
172             .iterator()
173             .next();
174     Assert.assertTrue(
175         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
176             .matcher(apiClientHeaderKey)
177             .matches());
178   }
179 
180   @Test
createDeviceRegistryExceptionTest2()181   public void createDeviceRegistryExceptionTest2() throws Exception {
182     ApiException exception =
183         ApiExceptionFactory.createException(
184             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
185     mockService.addException(exception);
186 
187     try {
188       String parent = "projects/project-5833/locations/location-5833";
189       DeviceRegistry deviceRegistry = DeviceRegistry.newBuilder().build();
190       client.createDeviceRegistry(parent, deviceRegistry);
191       Assert.fail("No exception raised");
192     } catch (InvalidArgumentException e) {
193       // Expected exception.
194     }
195   }
196 
197   @Test
getDeviceRegistryTest()198   public void getDeviceRegistryTest() throws Exception {
199     DeviceRegistry expectedResponse =
200         DeviceRegistry.newBuilder()
201             .setId("id3355")
202             .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
203             .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
204             .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
205             .setMqttConfig(MqttConfig.newBuilder().build())
206             .setHttpConfig(HttpConfig.newBuilder().build())
207             .setLogLevel(LogLevel.forNumber(0))
208             .addAllCredentials(new ArrayList<RegistryCredential>())
209             .build();
210     mockService.addResponse(expectedResponse);
211 
212     RegistryName name = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
213 
214     DeviceRegistry actualResponse = client.getDeviceRegistry(name);
215     Assert.assertEquals(expectedResponse, actualResponse);
216 
217     List<String> actualRequests = mockService.getRequestPaths();
218     Assert.assertEquals(1, actualRequests.size());
219 
220     String apiClientHeaderKey =
221         mockService
222             .getRequestHeaders()
223             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
224             .iterator()
225             .next();
226     Assert.assertTrue(
227         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
228             .matcher(apiClientHeaderKey)
229             .matches());
230   }
231 
232   @Test
getDeviceRegistryExceptionTest()233   public void getDeviceRegistryExceptionTest() throws Exception {
234     ApiException exception =
235         ApiExceptionFactory.createException(
236             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
237     mockService.addException(exception);
238 
239     try {
240       RegistryName name = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
241       client.getDeviceRegistry(name);
242       Assert.fail("No exception raised");
243     } catch (InvalidArgumentException e) {
244       // Expected exception.
245     }
246   }
247 
248   @Test
getDeviceRegistryTest2()249   public void getDeviceRegistryTest2() throws Exception {
250     DeviceRegistry expectedResponse =
251         DeviceRegistry.newBuilder()
252             .setId("id3355")
253             .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
254             .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
255             .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
256             .setMqttConfig(MqttConfig.newBuilder().build())
257             .setHttpConfig(HttpConfig.newBuilder().build())
258             .setLogLevel(LogLevel.forNumber(0))
259             .addAllCredentials(new ArrayList<RegistryCredential>())
260             .build();
261     mockService.addResponse(expectedResponse);
262 
263     String name = "projects/project-5653/locations/location-5653/registries/registrie-5653";
264 
265     DeviceRegistry actualResponse = client.getDeviceRegistry(name);
266     Assert.assertEquals(expectedResponse, actualResponse);
267 
268     List<String> actualRequests = mockService.getRequestPaths();
269     Assert.assertEquals(1, actualRequests.size());
270 
271     String apiClientHeaderKey =
272         mockService
273             .getRequestHeaders()
274             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
275             .iterator()
276             .next();
277     Assert.assertTrue(
278         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
279             .matcher(apiClientHeaderKey)
280             .matches());
281   }
282 
283   @Test
getDeviceRegistryExceptionTest2()284   public void getDeviceRegistryExceptionTest2() throws Exception {
285     ApiException exception =
286         ApiExceptionFactory.createException(
287             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
288     mockService.addException(exception);
289 
290     try {
291       String name = "projects/project-5653/locations/location-5653/registries/registrie-5653";
292       client.getDeviceRegistry(name);
293       Assert.fail("No exception raised");
294     } catch (InvalidArgumentException e) {
295       // Expected exception.
296     }
297   }
298 
299   @Test
updateDeviceRegistryTest()300   public void updateDeviceRegistryTest() throws Exception {
301     DeviceRegistry expectedResponse =
302         DeviceRegistry.newBuilder()
303             .setId("id3355")
304             .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
305             .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
306             .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
307             .setMqttConfig(MqttConfig.newBuilder().build())
308             .setHttpConfig(HttpConfig.newBuilder().build())
309             .setLogLevel(LogLevel.forNumber(0))
310             .addAllCredentials(new ArrayList<RegistryCredential>())
311             .build();
312     mockService.addResponse(expectedResponse);
313 
314     DeviceRegistry deviceRegistry =
315         DeviceRegistry.newBuilder()
316             .setId("id3355")
317             .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
318             .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
319             .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
320             .setMqttConfig(MqttConfig.newBuilder().build())
321             .setHttpConfig(HttpConfig.newBuilder().build())
322             .setLogLevel(LogLevel.forNumber(0))
323             .addAllCredentials(new ArrayList<RegistryCredential>())
324             .build();
325     FieldMask updateMask = FieldMask.newBuilder().build();
326 
327     DeviceRegistry actualResponse = client.updateDeviceRegistry(deviceRegistry, updateMask);
328     Assert.assertEquals(expectedResponse, actualResponse);
329 
330     List<String> actualRequests = mockService.getRequestPaths();
331     Assert.assertEquals(1, actualRequests.size());
332 
333     String apiClientHeaderKey =
334         mockService
335             .getRequestHeaders()
336             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
337             .iterator()
338             .next();
339     Assert.assertTrue(
340         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
341             .matcher(apiClientHeaderKey)
342             .matches());
343   }
344 
345   @Test
updateDeviceRegistryExceptionTest()346   public void updateDeviceRegistryExceptionTest() throws Exception {
347     ApiException exception =
348         ApiExceptionFactory.createException(
349             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
350     mockService.addException(exception);
351 
352     try {
353       DeviceRegistry deviceRegistry =
354           DeviceRegistry.newBuilder()
355               .setId("id3355")
356               .setName(RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]").toString())
357               .addAllEventNotificationConfigs(new ArrayList<EventNotificationConfig>())
358               .setStateNotificationConfig(StateNotificationConfig.newBuilder().build())
359               .setMqttConfig(MqttConfig.newBuilder().build())
360               .setHttpConfig(HttpConfig.newBuilder().build())
361               .setLogLevel(LogLevel.forNumber(0))
362               .addAllCredentials(new ArrayList<RegistryCredential>())
363               .build();
364       FieldMask updateMask = FieldMask.newBuilder().build();
365       client.updateDeviceRegistry(deviceRegistry, updateMask);
366       Assert.fail("No exception raised");
367     } catch (InvalidArgumentException e) {
368       // Expected exception.
369     }
370   }
371 
372   @Test
deleteDeviceRegistryTest()373   public void deleteDeviceRegistryTest() throws Exception {
374     Empty expectedResponse = Empty.newBuilder().build();
375     mockService.addResponse(expectedResponse);
376 
377     RegistryName name = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
378 
379     client.deleteDeviceRegistry(name);
380 
381     List<String> actualRequests = mockService.getRequestPaths();
382     Assert.assertEquals(1, actualRequests.size());
383 
384     String apiClientHeaderKey =
385         mockService
386             .getRequestHeaders()
387             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
388             .iterator()
389             .next();
390     Assert.assertTrue(
391         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
392             .matcher(apiClientHeaderKey)
393             .matches());
394   }
395 
396   @Test
deleteDeviceRegistryExceptionTest()397   public void deleteDeviceRegistryExceptionTest() throws Exception {
398     ApiException exception =
399         ApiExceptionFactory.createException(
400             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
401     mockService.addException(exception);
402 
403     try {
404       RegistryName name = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
405       client.deleteDeviceRegistry(name);
406       Assert.fail("No exception raised");
407     } catch (InvalidArgumentException e) {
408       // Expected exception.
409     }
410   }
411 
412   @Test
deleteDeviceRegistryTest2()413   public void deleteDeviceRegistryTest2() throws Exception {
414     Empty expectedResponse = Empty.newBuilder().build();
415     mockService.addResponse(expectedResponse);
416 
417     String name = "projects/project-5653/locations/location-5653/registries/registrie-5653";
418 
419     client.deleteDeviceRegistry(name);
420 
421     List<String> actualRequests = mockService.getRequestPaths();
422     Assert.assertEquals(1, actualRequests.size());
423 
424     String apiClientHeaderKey =
425         mockService
426             .getRequestHeaders()
427             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
428             .iterator()
429             .next();
430     Assert.assertTrue(
431         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
432             .matcher(apiClientHeaderKey)
433             .matches());
434   }
435 
436   @Test
deleteDeviceRegistryExceptionTest2()437   public void deleteDeviceRegistryExceptionTest2() throws Exception {
438     ApiException exception =
439         ApiExceptionFactory.createException(
440             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
441     mockService.addException(exception);
442 
443     try {
444       String name = "projects/project-5653/locations/location-5653/registries/registrie-5653";
445       client.deleteDeviceRegistry(name);
446       Assert.fail("No exception raised");
447     } catch (InvalidArgumentException e) {
448       // Expected exception.
449     }
450   }
451 
452   @Test
listDeviceRegistriesTest()453   public void listDeviceRegistriesTest() throws Exception {
454     DeviceRegistry responsesElement = DeviceRegistry.newBuilder().build();
455     ListDeviceRegistriesResponse expectedResponse =
456         ListDeviceRegistriesResponse.newBuilder()
457             .setNextPageToken("")
458             .addAllDeviceRegistries(Arrays.asList(responsesElement))
459             .build();
460     mockService.addResponse(expectedResponse);
461 
462     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
463 
464     ListDeviceRegistriesPagedResponse pagedListResponse = client.listDeviceRegistries(parent);
465 
466     List<DeviceRegistry> resources = Lists.newArrayList(pagedListResponse.iterateAll());
467 
468     Assert.assertEquals(1, resources.size());
469     Assert.assertEquals(expectedResponse.getDeviceRegistriesList().get(0), resources.get(0));
470 
471     List<String> actualRequests = mockService.getRequestPaths();
472     Assert.assertEquals(1, actualRequests.size());
473 
474     String apiClientHeaderKey =
475         mockService
476             .getRequestHeaders()
477             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
478             .iterator()
479             .next();
480     Assert.assertTrue(
481         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
482             .matcher(apiClientHeaderKey)
483             .matches());
484   }
485 
486   @Test
listDeviceRegistriesExceptionTest()487   public void listDeviceRegistriesExceptionTest() throws Exception {
488     ApiException exception =
489         ApiExceptionFactory.createException(
490             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
491     mockService.addException(exception);
492 
493     try {
494       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
495       client.listDeviceRegistries(parent);
496       Assert.fail("No exception raised");
497     } catch (InvalidArgumentException e) {
498       // Expected exception.
499     }
500   }
501 
502   @Test
listDeviceRegistriesTest2()503   public void listDeviceRegistriesTest2() throws Exception {
504     DeviceRegistry responsesElement = DeviceRegistry.newBuilder().build();
505     ListDeviceRegistriesResponse expectedResponse =
506         ListDeviceRegistriesResponse.newBuilder()
507             .setNextPageToken("")
508             .addAllDeviceRegistries(Arrays.asList(responsesElement))
509             .build();
510     mockService.addResponse(expectedResponse);
511 
512     String parent = "projects/project-5833/locations/location-5833";
513 
514     ListDeviceRegistriesPagedResponse pagedListResponse = client.listDeviceRegistries(parent);
515 
516     List<DeviceRegistry> resources = Lists.newArrayList(pagedListResponse.iterateAll());
517 
518     Assert.assertEquals(1, resources.size());
519     Assert.assertEquals(expectedResponse.getDeviceRegistriesList().get(0), resources.get(0));
520 
521     List<String> actualRequests = mockService.getRequestPaths();
522     Assert.assertEquals(1, actualRequests.size());
523 
524     String apiClientHeaderKey =
525         mockService
526             .getRequestHeaders()
527             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
528             .iterator()
529             .next();
530     Assert.assertTrue(
531         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
532             .matcher(apiClientHeaderKey)
533             .matches());
534   }
535 
536   @Test
listDeviceRegistriesExceptionTest2()537   public void listDeviceRegistriesExceptionTest2() throws Exception {
538     ApiException exception =
539         ApiExceptionFactory.createException(
540             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
541     mockService.addException(exception);
542 
543     try {
544       String parent = "projects/project-5833/locations/location-5833";
545       client.listDeviceRegistries(parent);
546       Assert.fail("No exception raised");
547     } catch (InvalidArgumentException e) {
548       // Expected exception.
549     }
550   }
551 
552   @Test
createDeviceTest()553   public void createDeviceTest() throws Exception {
554     Device expectedResponse =
555         Device.newBuilder()
556             .setId("id3355")
557             .setName(DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
558             .setNumId(-1034366860)
559             .addAllCredentials(new ArrayList<DeviceCredential>())
560             .setLastHeartbeatTime(Timestamp.newBuilder().build())
561             .setLastEventTime(Timestamp.newBuilder().build())
562             .setLastStateTime(Timestamp.newBuilder().build())
563             .setLastConfigAckTime(Timestamp.newBuilder().build())
564             .setLastConfigSendTime(Timestamp.newBuilder().build())
565             .setBlocked(true)
566             .setLastErrorTime(Timestamp.newBuilder().build())
567             .setLastErrorStatus(Status.newBuilder().build())
568             .setConfig(DeviceConfig.newBuilder().build())
569             .setState(DeviceState.newBuilder().build())
570             .setLogLevel(LogLevel.forNumber(0))
571             .putAllMetadata(new HashMap<String, String>())
572             .setGatewayConfig(GatewayConfig.newBuilder().build())
573             .build();
574     mockService.addResponse(expectedResponse);
575 
576     RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
577     Device device = Device.newBuilder().build();
578 
579     Device actualResponse = client.createDevice(parent, device);
580     Assert.assertEquals(expectedResponse, actualResponse);
581 
582     List<String> actualRequests = mockService.getRequestPaths();
583     Assert.assertEquals(1, actualRequests.size());
584 
585     String apiClientHeaderKey =
586         mockService
587             .getRequestHeaders()
588             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
589             .iterator()
590             .next();
591     Assert.assertTrue(
592         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
593             .matcher(apiClientHeaderKey)
594             .matches());
595   }
596 
597   @Test
createDeviceExceptionTest()598   public void createDeviceExceptionTest() throws Exception {
599     ApiException exception =
600         ApiExceptionFactory.createException(
601             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
602     mockService.addException(exception);
603 
604     try {
605       RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
606       Device device = Device.newBuilder().build();
607       client.createDevice(parent, device);
608       Assert.fail("No exception raised");
609     } catch (InvalidArgumentException e) {
610       // Expected exception.
611     }
612   }
613 
614   @Test
createDeviceTest2()615   public void createDeviceTest2() throws Exception {
616     Device expectedResponse =
617         Device.newBuilder()
618             .setId("id3355")
619             .setName(DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
620             .setNumId(-1034366860)
621             .addAllCredentials(new ArrayList<DeviceCredential>())
622             .setLastHeartbeatTime(Timestamp.newBuilder().build())
623             .setLastEventTime(Timestamp.newBuilder().build())
624             .setLastStateTime(Timestamp.newBuilder().build())
625             .setLastConfigAckTime(Timestamp.newBuilder().build())
626             .setLastConfigSendTime(Timestamp.newBuilder().build())
627             .setBlocked(true)
628             .setLastErrorTime(Timestamp.newBuilder().build())
629             .setLastErrorStatus(Status.newBuilder().build())
630             .setConfig(DeviceConfig.newBuilder().build())
631             .setState(DeviceState.newBuilder().build())
632             .setLogLevel(LogLevel.forNumber(0))
633             .putAllMetadata(new HashMap<String, String>())
634             .setGatewayConfig(GatewayConfig.newBuilder().build())
635             .build();
636     mockService.addResponse(expectedResponse);
637 
638     String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
639     Device device = Device.newBuilder().build();
640 
641     Device actualResponse = client.createDevice(parent, device);
642     Assert.assertEquals(expectedResponse, actualResponse);
643 
644     List<String> actualRequests = mockService.getRequestPaths();
645     Assert.assertEquals(1, actualRequests.size());
646 
647     String apiClientHeaderKey =
648         mockService
649             .getRequestHeaders()
650             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
651             .iterator()
652             .next();
653     Assert.assertTrue(
654         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
655             .matcher(apiClientHeaderKey)
656             .matches());
657   }
658 
659   @Test
createDeviceExceptionTest2()660   public void createDeviceExceptionTest2() throws Exception {
661     ApiException exception =
662         ApiExceptionFactory.createException(
663             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
664     mockService.addException(exception);
665 
666     try {
667       String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
668       Device device = Device.newBuilder().build();
669       client.createDevice(parent, device);
670       Assert.fail("No exception raised");
671     } catch (InvalidArgumentException e) {
672       // Expected exception.
673     }
674   }
675 
676   @Test
getDeviceTest()677   public void getDeviceTest() throws Exception {
678     Device expectedResponse =
679         Device.newBuilder()
680             .setId("id3355")
681             .setName(DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
682             .setNumId(-1034366860)
683             .addAllCredentials(new ArrayList<DeviceCredential>())
684             .setLastHeartbeatTime(Timestamp.newBuilder().build())
685             .setLastEventTime(Timestamp.newBuilder().build())
686             .setLastStateTime(Timestamp.newBuilder().build())
687             .setLastConfigAckTime(Timestamp.newBuilder().build())
688             .setLastConfigSendTime(Timestamp.newBuilder().build())
689             .setBlocked(true)
690             .setLastErrorTime(Timestamp.newBuilder().build())
691             .setLastErrorStatus(Status.newBuilder().build())
692             .setConfig(DeviceConfig.newBuilder().build())
693             .setState(DeviceState.newBuilder().build())
694             .setLogLevel(LogLevel.forNumber(0))
695             .putAllMetadata(new HashMap<String, String>())
696             .setGatewayConfig(GatewayConfig.newBuilder().build())
697             .build();
698     mockService.addResponse(expectedResponse);
699 
700     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
701 
702     Device actualResponse = client.getDevice(name);
703     Assert.assertEquals(expectedResponse, actualResponse);
704 
705     List<String> actualRequests = mockService.getRequestPaths();
706     Assert.assertEquals(1, actualRequests.size());
707 
708     String apiClientHeaderKey =
709         mockService
710             .getRequestHeaders()
711             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
712             .iterator()
713             .next();
714     Assert.assertTrue(
715         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
716             .matcher(apiClientHeaderKey)
717             .matches());
718   }
719 
720   @Test
getDeviceExceptionTest()721   public void getDeviceExceptionTest() throws Exception {
722     ApiException exception =
723         ApiExceptionFactory.createException(
724             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
725     mockService.addException(exception);
726 
727     try {
728       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
729       client.getDevice(name);
730       Assert.fail("No exception raised");
731     } catch (InvalidArgumentException e) {
732       // Expected exception.
733     }
734   }
735 
736   @Test
getDeviceTest2()737   public void getDeviceTest2() throws Exception {
738     Device expectedResponse =
739         Device.newBuilder()
740             .setId("id3355")
741             .setName(DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
742             .setNumId(-1034366860)
743             .addAllCredentials(new ArrayList<DeviceCredential>())
744             .setLastHeartbeatTime(Timestamp.newBuilder().build())
745             .setLastEventTime(Timestamp.newBuilder().build())
746             .setLastStateTime(Timestamp.newBuilder().build())
747             .setLastConfigAckTime(Timestamp.newBuilder().build())
748             .setLastConfigSendTime(Timestamp.newBuilder().build())
749             .setBlocked(true)
750             .setLastErrorTime(Timestamp.newBuilder().build())
751             .setLastErrorStatus(Status.newBuilder().build())
752             .setConfig(DeviceConfig.newBuilder().build())
753             .setState(DeviceState.newBuilder().build())
754             .setLogLevel(LogLevel.forNumber(0))
755             .putAllMetadata(new HashMap<String, String>())
756             .setGatewayConfig(GatewayConfig.newBuilder().build())
757             .build();
758     mockService.addResponse(expectedResponse);
759 
760     String name =
761         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
762 
763     Device actualResponse = client.getDevice(name);
764     Assert.assertEquals(expectedResponse, actualResponse);
765 
766     List<String> actualRequests = mockService.getRequestPaths();
767     Assert.assertEquals(1, actualRequests.size());
768 
769     String apiClientHeaderKey =
770         mockService
771             .getRequestHeaders()
772             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
773             .iterator()
774             .next();
775     Assert.assertTrue(
776         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
777             .matcher(apiClientHeaderKey)
778             .matches());
779   }
780 
781   @Test
getDeviceExceptionTest2()782   public void getDeviceExceptionTest2() throws Exception {
783     ApiException exception =
784         ApiExceptionFactory.createException(
785             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
786     mockService.addException(exception);
787 
788     try {
789       String name =
790           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
791       client.getDevice(name);
792       Assert.fail("No exception raised");
793     } catch (InvalidArgumentException e) {
794       // Expected exception.
795     }
796   }
797 
798   @Test
updateDeviceTest()799   public void updateDeviceTest() throws Exception {
800     Device expectedResponse =
801         Device.newBuilder()
802             .setId("id3355")
803             .setName(DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
804             .setNumId(-1034366860)
805             .addAllCredentials(new ArrayList<DeviceCredential>())
806             .setLastHeartbeatTime(Timestamp.newBuilder().build())
807             .setLastEventTime(Timestamp.newBuilder().build())
808             .setLastStateTime(Timestamp.newBuilder().build())
809             .setLastConfigAckTime(Timestamp.newBuilder().build())
810             .setLastConfigSendTime(Timestamp.newBuilder().build())
811             .setBlocked(true)
812             .setLastErrorTime(Timestamp.newBuilder().build())
813             .setLastErrorStatus(Status.newBuilder().build())
814             .setConfig(DeviceConfig.newBuilder().build())
815             .setState(DeviceState.newBuilder().build())
816             .setLogLevel(LogLevel.forNumber(0))
817             .putAllMetadata(new HashMap<String, String>())
818             .setGatewayConfig(GatewayConfig.newBuilder().build())
819             .build();
820     mockService.addResponse(expectedResponse);
821 
822     Device device =
823         Device.newBuilder()
824             .setId("id3355")
825             .setName(DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
826             .setNumId(-1034366860)
827             .addAllCredentials(new ArrayList<DeviceCredential>())
828             .setLastHeartbeatTime(Timestamp.newBuilder().build())
829             .setLastEventTime(Timestamp.newBuilder().build())
830             .setLastStateTime(Timestamp.newBuilder().build())
831             .setLastConfigAckTime(Timestamp.newBuilder().build())
832             .setLastConfigSendTime(Timestamp.newBuilder().build())
833             .setBlocked(true)
834             .setLastErrorTime(Timestamp.newBuilder().build())
835             .setLastErrorStatus(Status.newBuilder().build())
836             .setConfig(DeviceConfig.newBuilder().build())
837             .setState(DeviceState.newBuilder().build())
838             .setLogLevel(LogLevel.forNumber(0))
839             .putAllMetadata(new HashMap<String, String>())
840             .setGatewayConfig(GatewayConfig.newBuilder().build())
841             .build();
842     FieldMask updateMask = FieldMask.newBuilder().build();
843 
844     Device actualResponse = client.updateDevice(device, updateMask);
845     Assert.assertEquals(expectedResponse, actualResponse);
846 
847     List<String> actualRequests = mockService.getRequestPaths();
848     Assert.assertEquals(1, actualRequests.size());
849 
850     String apiClientHeaderKey =
851         mockService
852             .getRequestHeaders()
853             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
854             .iterator()
855             .next();
856     Assert.assertTrue(
857         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
858             .matcher(apiClientHeaderKey)
859             .matches());
860   }
861 
862   @Test
updateDeviceExceptionTest()863   public void updateDeviceExceptionTest() throws Exception {
864     ApiException exception =
865         ApiExceptionFactory.createException(
866             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
867     mockService.addException(exception);
868 
869     try {
870       Device device =
871           Device.newBuilder()
872               .setId("id3355")
873               .setName(
874                   DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]").toString())
875               .setNumId(-1034366860)
876               .addAllCredentials(new ArrayList<DeviceCredential>())
877               .setLastHeartbeatTime(Timestamp.newBuilder().build())
878               .setLastEventTime(Timestamp.newBuilder().build())
879               .setLastStateTime(Timestamp.newBuilder().build())
880               .setLastConfigAckTime(Timestamp.newBuilder().build())
881               .setLastConfigSendTime(Timestamp.newBuilder().build())
882               .setBlocked(true)
883               .setLastErrorTime(Timestamp.newBuilder().build())
884               .setLastErrorStatus(Status.newBuilder().build())
885               .setConfig(DeviceConfig.newBuilder().build())
886               .setState(DeviceState.newBuilder().build())
887               .setLogLevel(LogLevel.forNumber(0))
888               .putAllMetadata(new HashMap<String, String>())
889               .setGatewayConfig(GatewayConfig.newBuilder().build())
890               .build();
891       FieldMask updateMask = FieldMask.newBuilder().build();
892       client.updateDevice(device, updateMask);
893       Assert.fail("No exception raised");
894     } catch (InvalidArgumentException e) {
895       // Expected exception.
896     }
897   }
898 
899   @Test
deleteDeviceTest()900   public void deleteDeviceTest() throws Exception {
901     Empty expectedResponse = Empty.newBuilder().build();
902     mockService.addResponse(expectedResponse);
903 
904     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
905 
906     client.deleteDevice(name);
907 
908     List<String> actualRequests = mockService.getRequestPaths();
909     Assert.assertEquals(1, actualRequests.size());
910 
911     String apiClientHeaderKey =
912         mockService
913             .getRequestHeaders()
914             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
915             .iterator()
916             .next();
917     Assert.assertTrue(
918         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
919             .matcher(apiClientHeaderKey)
920             .matches());
921   }
922 
923   @Test
deleteDeviceExceptionTest()924   public void deleteDeviceExceptionTest() throws Exception {
925     ApiException exception =
926         ApiExceptionFactory.createException(
927             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
928     mockService.addException(exception);
929 
930     try {
931       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
932       client.deleteDevice(name);
933       Assert.fail("No exception raised");
934     } catch (InvalidArgumentException e) {
935       // Expected exception.
936     }
937   }
938 
939   @Test
deleteDeviceTest2()940   public void deleteDeviceTest2() throws Exception {
941     Empty expectedResponse = Empty.newBuilder().build();
942     mockService.addResponse(expectedResponse);
943 
944     String name =
945         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
946 
947     client.deleteDevice(name);
948 
949     List<String> actualRequests = mockService.getRequestPaths();
950     Assert.assertEquals(1, actualRequests.size());
951 
952     String apiClientHeaderKey =
953         mockService
954             .getRequestHeaders()
955             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
956             .iterator()
957             .next();
958     Assert.assertTrue(
959         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
960             .matcher(apiClientHeaderKey)
961             .matches());
962   }
963 
964   @Test
deleteDeviceExceptionTest2()965   public void deleteDeviceExceptionTest2() throws Exception {
966     ApiException exception =
967         ApiExceptionFactory.createException(
968             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
969     mockService.addException(exception);
970 
971     try {
972       String name =
973           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
974       client.deleteDevice(name);
975       Assert.fail("No exception raised");
976     } catch (InvalidArgumentException e) {
977       // Expected exception.
978     }
979   }
980 
981   @Test
listDevicesTest()982   public void listDevicesTest() throws Exception {
983     Device responsesElement = Device.newBuilder().build();
984     ListDevicesResponse expectedResponse =
985         ListDevicesResponse.newBuilder()
986             .setNextPageToken("")
987             .addAllDevices(Arrays.asList(responsesElement))
988             .build();
989     mockService.addResponse(expectedResponse);
990 
991     RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
992 
993     ListDevicesPagedResponse pagedListResponse = client.listDevices(parent);
994 
995     List<Device> resources = Lists.newArrayList(pagedListResponse.iterateAll());
996 
997     Assert.assertEquals(1, resources.size());
998     Assert.assertEquals(expectedResponse.getDevicesList().get(0), resources.get(0));
999 
1000     List<String> actualRequests = mockService.getRequestPaths();
1001     Assert.assertEquals(1, actualRequests.size());
1002 
1003     String apiClientHeaderKey =
1004         mockService
1005             .getRequestHeaders()
1006             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1007             .iterator()
1008             .next();
1009     Assert.assertTrue(
1010         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1011             .matcher(apiClientHeaderKey)
1012             .matches());
1013   }
1014 
1015   @Test
listDevicesExceptionTest()1016   public void listDevicesExceptionTest() throws Exception {
1017     ApiException exception =
1018         ApiExceptionFactory.createException(
1019             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1020     mockService.addException(exception);
1021 
1022     try {
1023       RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1024       client.listDevices(parent);
1025       Assert.fail("No exception raised");
1026     } catch (InvalidArgumentException e) {
1027       // Expected exception.
1028     }
1029   }
1030 
1031   @Test
listDevicesTest2()1032   public void listDevicesTest2() throws Exception {
1033     Device responsesElement = Device.newBuilder().build();
1034     ListDevicesResponse expectedResponse =
1035         ListDevicesResponse.newBuilder()
1036             .setNextPageToken("")
1037             .addAllDevices(Arrays.asList(responsesElement))
1038             .build();
1039     mockService.addResponse(expectedResponse);
1040 
1041     String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
1042 
1043     ListDevicesPagedResponse pagedListResponse = client.listDevices(parent);
1044 
1045     List<Device> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1046 
1047     Assert.assertEquals(1, resources.size());
1048     Assert.assertEquals(expectedResponse.getDevicesList().get(0), resources.get(0));
1049 
1050     List<String> actualRequests = mockService.getRequestPaths();
1051     Assert.assertEquals(1, actualRequests.size());
1052 
1053     String apiClientHeaderKey =
1054         mockService
1055             .getRequestHeaders()
1056             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1057             .iterator()
1058             .next();
1059     Assert.assertTrue(
1060         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1061             .matcher(apiClientHeaderKey)
1062             .matches());
1063   }
1064 
1065   @Test
listDevicesExceptionTest2()1066   public void listDevicesExceptionTest2() throws Exception {
1067     ApiException exception =
1068         ApiExceptionFactory.createException(
1069             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1070     mockService.addException(exception);
1071 
1072     try {
1073       String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
1074       client.listDevices(parent);
1075       Assert.fail("No exception raised");
1076     } catch (InvalidArgumentException e) {
1077       // Expected exception.
1078     }
1079   }
1080 
1081   @Test
modifyCloudToDeviceConfigTest()1082   public void modifyCloudToDeviceConfigTest() throws Exception {
1083     DeviceConfig expectedResponse =
1084         DeviceConfig.newBuilder()
1085             .setVersion(351608024)
1086             .setCloudUpdateTime(Timestamp.newBuilder().build())
1087             .setDeviceAckTime(Timestamp.newBuilder().build())
1088             .setBinaryData(ByteString.EMPTY)
1089             .build();
1090     mockService.addResponse(expectedResponse);
1091 
1092     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1093     ByteString binaryData = ByteString.EMPTY;
1094 
1095     DeviceConfig actualResponse = client.modifyCloudToDeviceConfig(name, binaryData);
1096     Assert.assertEquals(expectedResponse, actualResponse);
1097 
1098     List<String> actualRequests = mockService.getRequestPaths();
1099     Assert.assertEquals(1, actualRequests.size());
1100 
1101     String apiClientHeaderKey =
1102         mockService
1103             .getRequestHeaders()
1104             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1105             .iterator()
1106             .next();
1107     Assert.assertTrue(
1108         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1109             .matcher(apiClientHeaderKey)
1110             .matches());
1111   }
1112 
1113   @Test
modifyCloudToDeviceConfigExceptionTest()1114   public void modifyCloudToDeviceConfigExceptionTest() throws Exception {
1115     ApiException exception =
1116         ApiExceptionFactory.createException(
1117             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1118     mockService.addException(exception);
1119 
1120     try {
1121       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1122       ByteString binaryData = ByteString.EMPTY;
1123       client.modifyCloudToDeviceConfig(name, binaryData);
1124       Assert.fail("No exception raised");
1125     } catch (InvalidArgumentException e) {
1126       // Expected exception.
1127     }
1128   }
1129 
1130   @Test
modifyCloudToDeviceConfigTest2()1131   public void modifyCloudToDeviceConfigTest2() throws Exception {
1132     DeviceConfig expectedResponse =
1133         DeviceConfig.newBuilder()
1134             .setVersion(351608024)
1135             .setCloudUpdateTime(Timestamp.newBuilder().build())
1136             .setDeviceAckTime(Timestamp.newBuilder().build())
1137             .setBinaryData(ByteString.EMPTY)
1138             .build();
1139     mockService.addResponse(expectedResponse);
1140 
1141     String name =
1142         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1143     ByteString binaryData = ByteString.EMPTY;
1144 
1145     DeviceConfig actualResponse = client.modifyCloudToDeviceConfig(name, binaryData);
1146     Assert.assertEquals(expectedResponse, actualResponse);
1147 
1148     List<String> actualRequests = mockService.getRequestPaths();
1149     Assert.assertEquals(1, actualRequests.size());
1150 
1151     String apiClientHeaderKey =
1152         mockService
1153             .getRequestHeaders()
1154             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1155             .iterator()
1156             .next();
1157     Assert.assertTrue(
1158         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1159             .matcher(apiClientHeaderKey)
1160             .matches());
1161   }
1162 
1163   @Test
modifyCloudToDeviceConfigExceptionTest2()1164   public void modifyCloudToDeviceConfigExceptionTest2() throws Exception {
1165     ApiException exception =
1166         ApiExceptionFactory.createException(
1167             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1168     mockService.addException(exception);
1169 
1170     try {
1171       String name =
1172           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1173       ByteString binaryData = ByteString.EMPTY;
1174       client.modifyCloudToDeviceConfig(name, binaryData);
1175       Assert.fail("No exception raised");
1176     } catch (InvalidArgumentException e) {
1177       // Expected exception.
1178     }
1179   }
1180 
1181   @Test
listDeviceConfigVersionsTest()1182   public void listDeviceConfigVersionsTest() throws Exception {
1183     ListDeviceConfigVersionsResponse expectedResponse =
1184         ListDeviceConfigVersionsResponse.newBuilder()
1185             .addAllDeviceConfigs(new ArrayList<DeviceConfig>())
1186             .build();
1187     mockService.addResponse(expectedResponse);
1188 
1189     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1190 
1191     ListDeviceConfigVersionsResponse actualResponse = client.listDeviceConfigVersions(name);
1192     Assert.assertEquals(expectedResponse, actualResponse);
1193 
1194     List<String> actualRequests = mockService.getRequestPaths();
1195     Assert.assertEquals(1, actualRequests.size());
1196 
1197     String apiClientHeaderKey =
1198         mockService
1199             .getRequestHeaders()
1200             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1201             .iterator()
1202             .next();
1203     Assert.assertTrue(
1204         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1205             .matcher(apiClientHeaderKey)
1206             .matches());
1207   }
1208 
1209   @Test
listDeviceConfigVersionsExceptionTest()1210   public void listDeviceConfigVersionsExceptionTest() throws Exception {
1211     ApiException exception =
1212         ApiExceptionFactory.createException(
1213             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1214     mockService.addException(exception);
1215 
1216     try {
1217       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1218       client.listDeviceConfigVersions(name);
1219       Assert.fail("No exception raised");
1220     } catch (InvalidArgumentException e) {
1221       // Expected exception.
1222     }
1223   }
1224 
1225   @Test
listDeviceConfigVersionsTest2()1226   public void listDeviceConfigVersionsTest2() throws Exception {
1227     ListDeviceConfigVersionsResponse expectedResponse =
1228         ListDeviceConfigVersionsResponse.newBuilder()
1229             .addAllDeviceConfigs(new ArrayList<DeviceConfig>())
1230             .build();
1231     mockService.addResponse(expectedResponse);
1232 
1233     String name =
1234         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1235 
1236     ListDeviceConfigVersionsResponse actualResponse = client.listDeviceConfigVersions(name);
1237     Assert.assertEquals(expectedResponse, actualResponse);
1238 
1239     List<String> actualRequests = mockService.getRequestPaths();
1240     Assert.assertEquals(1, actualRequests.size());
1241 
1242     String apiClientHeaderKey =
1243         mockService
1244             .getRequestHeaders()
1245             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1246             .iterator()
1247             .next();
1248     Assert.assertTrue(
1249         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1250             .matcher(apiClientHeaderKey)
1251             .matches());
1252   }
1253 
1254   @Test
listDeviceConfigVersionsExceptionTest2()1255   public void listDeviceConfigVersionsExceptionTest2() throws Exception {
1256     ApiException exception =
1257         ApiExceptionFactory.createException(
1258             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1259     mockService.addException(exception);
1260 
1261     try {
1262       String name =
1263           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1264       client.listDeviceConfigVersions(name);
1265       Assert.fail("No exception raised");
1266     } catch (InvalidArgumentException e) {
1267       // Expected exception.
1268     }
1269   }
1270 
1271   @Test
listDeviceStatesTest()1272   public void listDeviceStatesTest() throws Exception {
1273     ListDeviceStatesResponse expectedResponse =
1274         ListDeviceStatesResponse.newBuilder()
1275             .addAllDeviceStates(new ArrayList<DeviceState>())
1276             .build();
1277     mockService.addResponse(expectedResponse);
1278 
1279     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1280 
1281     ListDeviceStatesResponse actualResponse = client.listDeviceStates(name);
1282     Assert.assertEquals(expectedResponse, actualResponse);
1283 
1284     List<String> actualRequests = mockService.getRequestPaths();
1285     Assert.assertEquals(1, actualRequests.size());
1286 
1287     String apiClientHeaderKey =
1288         mockService
1289             .getRequestHeaders()
1290             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1291             .iterator()
1292             .next();
1293     Assert.assertTrue(
1294         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1295             .matcher(apiClientHeaderKey)
1296             .matches());
1297   }
1298 
1299   @Test
listDeviceStatesExceptionTest()1300   public void listDeviceStatesExceptionTest() throws Exception {
1301     ApiException exception =
1302         ApiExceptionFactory.createException(
1303             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1304     mockService.addException(exception);
1305 
1306     try {
1307       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1308       client.listDeviceStates(name);
1309       Assert.fail("No exception raised");
1310     } catch (InvalidArgumentException e) {
1311       // Expected exception.
1312     }
1313   }
1314 
1315   @Test
listDeviceStatesTest2()1316   public void listDeviceStatesTest2() throws Exception {
1317     ListDeviceStatesResponse expectedResponse =
1318         ListDeviceStatesResponse.newBuilder()
1319             .addAllDeviceStates(new ArrayList<DeviceState>())
1320             .build();
1321     mockService.addResponse(expectedResponse);
1322 
1323     String name =
1324         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1325 
1326     ListDeviceStatesResponse actualResponse = client.listDeviceStates(name);
1327     Assert.assertEquals(expectedResponse, actualResponse);
1328 
1329     List<String> actualRequests = mockService.getRequestPaths();
1330     Assert.assertEquals(1, actualRequests.size());
1331 
1332     String apiClientHeaderKey =
1333         mockService
1334             .getRequestHeaders()
1335             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1336             .iterator()
1337             .next();
1338     Assert.assertTrue(
1339         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1340             .matcher(apiClientHeaderKey)
1341             .matches());
1342   }
1343 
1344   @Test
listDeviceStatesExceptionTest2()1345   public void listDeviceStatesExceptionTest2() throws Exception {
1346     ApiException exception =
1347         ApiExceptionFactory.createException(
1348             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1349     mockService.addException(exception);
1350 
1351     try {
1352       String name =
1353           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1354       client.listDeviceStates(name);
1355       Assert.fail("No exception raised");
1356     } catch (InvalidArgumentException e) {
1357       // Expected exception.
1358     }
1359   }
1360 
1361   @Test
setIamPolicyTest()1362   public void setIamPolicyTest() throws Exception {
1363     Policy expectedResponse =
1364         Policy.newBuilder()
1365             .setVersion(351608024)
1366             .addAllBindings(new ArrayList<Binding>())
1367             .addAllAuditConfigs(new ArrayList<AuditConfig>())
1368             .setEtag(ByteString.EMPTY)
1369             .build();
1370     mockService.addResponse(expectedResponse);
1371 
1372     ResourceName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1373     Policy policy = Policy.newBuilder().build();
1374 
1375     Policy actualResponse = client.setIamPolicy(resource, policy);
1376     Assert.assertEquals(expectedResponse, actualResponse);
1377 
1378     List<String> actualRequests = mockService.getRequestPaths();
1379     Assert.assertEquals(1, actualRequests.size());
1380 
1381     String apiClientHeaderKey =
1382         mockService
1383             .getRequestHeaders()
1384             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1385             .iterator()
1386             .next();
1387     Assert.assertTrue(
1388         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1389             .matcher(apiClientHeaderKey)
1390             .matches());
1391   }
1392 
1393   @Test
setIamPolicyExceptionTest()1394   public void setIamPolicyExceptionTest() throws Exception {
1395     ApiException exception =
1396         ApiExceptionFactory.createException(
1397             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1398     mockService.addException(exception);
1399 
1400     try {
1401       ResourceName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1402       Policy policy = Policy.newBuilder().build();
1403       client.setIamPolicy(resource, policy);
1404       Assert.fail("No exception raised");
1405     } catch (InvalidArgumentException e) {
1406       // Expected exception.
1407     }
1408   }
1409 
1410   @Test
setIamPolicyTest2()1411   public void setIamPolicyTest2() throws Exception {
1412     Policy expectedResponse =
1413         Policy.newBuilder()
1414             .setVersion(351608024)
1415             .addAllBindings(new ArrayList<Binding>())
1416             .addAllAuditConfigs(new ArrayList<AuditConfig>())
1417             .setEtag(ByteString.EMPTY)
1418             .build();
1419     mockService.addResponse(expectedResponse);
1420 
1421     String resource = "projects/project-6248/locations/location-6248/registries/registrie-6248";
1422     Policy policy = Policy.newBuilder().build();
1423 
1424     Policy actualResponse = client.setIamPolicy(resource, policy);
1425     Assert.assertEquals(expectedResponse, actualResponse);
1426 
1427     List<String> actualRequests = mockService.getRequestPaths();
1428     Assert.assertEquals(1, actualRequests.size());
1429 
1430     String apiClientHeaderKey =
1431         mockService
1432             .getRequestHeaders()
1433             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1434             .iterator()
1435             .next();
1436     Assert.assertTrue(
1437         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1438             .matcher(apiClientHeaderKey)
1439             .matches());
1440   }
1441 
1442   @Test
setIamPolicyExceptionTest2()1443   public void setIamPolicyExceptionTest2() throws Exception {
1444     ApiException exception =
1445         ApiExceptionFactory.createException(
1446             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1447     mockService.addException(exception);
1448 
1449     try {
1450       String resource = "projects/project-6248/locations/location-6248/registries/registrie-6248";
1451       Policy policy = Policy.newBuilder().build();
1452       client.setIamPolicy(resource, policy);
1453       Assert.fail("No exception raised");
1454     } catch (InvalidArgumentException e) {
1455       // Expected exception.
1456     }
1457   }
1458 
1459   @Test
getIamPolicyTest()1460   public void getIamPolicyTest() throws Exception {
1461     Policy expectedResponse =
1462         Policy.newBuilder()
1463             .setVersion(351608024)
1464             .addAllBindings(new ArrayList<Binding>())
1465             .addAllAuditConfigs(new ArrayList<AuditConfig>())
1466             .setEtag(ByteString.EMPTY)
1467             .build();
1468     mockService.addResponse(expectedResponse);
1469 
1470     ResourceName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1471 
1472     Policy actualResponse = client.getIamPolicy(resource);
1473     Assert.assertEquals(expectedResponse, actualResponse);
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
getIamPolicyExceptionTest()1491   public void getIamPolicyExceptionTest() 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       ResourceName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1499       client.getIamPolicy(resource);
1500       Assert.fail("No exception raised");
1501     } catch (InvalidArgumentException e) {
1502       // Expected exception.
1503     }
1504   }
1505 
1506   @Test
getIamPolicyTest2()1507   public void getIamPolicyTest2() throws Exception {
1508     Policy expectedResponse =
1509         Policy.newBuilder()
1510             .setVersion(351608024)
1511             .addAllBindings(new ArrayList<Binding>())
1512             .addAllAuditConfigs(new ArrayList<AuditConfig>())
1513             .setEtag(ByteString.EMPTY)
1514             .build();
1515     mockService.addResponse(expectedResponse);
1516 
1517     String resource = "projects/project-6248/locations/location-6248/registries/registrie-6248";
1518 
1519     Policy actualResponse = client.getIamPolicy(resource);
1520     Assert.assertEquals(expectedResponse, actualResponse);
1521 
1522     List<String> actualRequests = mockService.getRequestPaths();
1523     Assert.assertEquals(1, actualRequests.size());
1524 
1525     String apiClientHeaderKey =
1526         mockService
1527             .getRequestHeaders()
1528             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1529             .iterator()
1530             .next();
1531     Assert.assertTrue(
1532         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1533             .matcher(apiClientHeaderKey)
1534             .matches());
1535   }
1536 
1537   @Test
getIamPolicyExceptionTest2()1538   public void getIamPolicyExceptionTest2() throws Exception {
1539     ApiException exception =
1540         ApiExceptionFactory.createException(
1541             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1542     mockService.addException(exception);
1543 
1544     try {
1545       String resource = "projects/project-6248/locations/location-6248/registries/registrie-6248";
1546       client.getIamPolicy(resource);
1547       Assert.fail("No exception raised");
1548     } catch (InvalidArgumentException e) {
1549       // Expected exception.
1550     }
1551   }
1552 
1553   @Test
testIamPermissionsTest()1554   public void testIamPermissionsTest() throws Exception {
1555     TestIamPermissionsResponse expectedResponse =
1556         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
1557     mockService.addResponse(expectedResponse);
1558 
1559     ResourceName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1560     List<String> permissions = new ArrayList<>();
1561 
1562     TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions);
1563     Assert.assertEquals(expectedResponse, actualResponse);
1564 
1565     List<String> actualRequests = mockService.getRequestPaths();
1566     Assert.assertEquals(1, actualRequests.size());
1567 
1568     String apiClientHeaderKey =
1569         mockService
1570             .getRequestHeaders()
1571             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1572             .iterator()
1573             .next();
1574     Assert.assertTrue(
1575         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1576             .matcher(apiClientHeaderKey)
1577             .matches());
1578   }
1579 
1580   @Test
testIamPermissionsExceptionTest()1581   public void testIamPermissionsExceptionTest() throws Exception {
1582     ApiException exception =
1583         ApiExceptionFactory.createException(
1584             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1585     mockService.addException(exception);
1586 
1587     try {
1588       ResourceName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1589       List<String> permissions = new ArrayList<>();
1590       client.testIamPermissions(resource, permissions);
1591       Assert.fail("No exception raised");
1592     } catch (InvalidArgumentException e) {
1593       // Expected exception.
1594     }
1595   }
1596 
1597   @Test
testIamPermissionsTest2()1598   public void testIamPermissionsTest2() throws Exception {
1599     TestIamPermissionsResponse expectedResponse =
1600         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
1601     mockService.addResponse(expectedResponse);
1602 
1603     String resource = "projects/project-6248/locations/location-6248/registries/registrie-6248";
1604     List<String> permissions = new ArrayList<>();
1605 
1606     TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions);
1607     Assert.assertEquals(expectedResponse, actualResponse);
1608 
1609     List<String> actualRequests = mockService.getRequestPaths();
1610     Assert.assertEquals(1, actualRequests.size());
1611 
1612     String apiClientHeaderKey =
1613         mockService
1614             .getRequestHeaders()
1615             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1616             .iterator()
1617             .next();
1618     Assert.assertTrue(
1619         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1620             .matcher(apiClientHeaderKey)
1621             .matches());
1622   }
1623 
1624   @Test
testIamPermissionsExceptionTest2()1625   public void testIamPermissionsExceptionTest2() throws Exception {
1626     ApiException exception =
1627         ApiExceptionFactory.createException(
1628             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1629     mockService.addException(exception);
1630 
1631     try {
1632       String resource = "projects/project-6248/locations/location-6248/registries/registrie-6248";
1633       List<String> permissions = new ArrayList<>();
1634       client.testIamPermissions(resource, permissions);
1635       Assert.fail("No exception raised");
1636     } catch (InvalidArgumentException e) {
1637       // Expected exception.
1638     }
1639   }
1640 
1641   @Test
sendCommandToDeviceTest()1642   public void sendCommandToDeviceTest() throws Exception {
1643     SendCommandToDeviceResponse expectedResponse = SendCommandToDeviceResponse.newBuilder().build();
1644     mockService.addResponse(expectedResponse);
1645 
1646     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1647     ByteString binaryData = ByteString.EMPTY;
1648 
1649     SendCommandToDeviceResponse actualResponse = client.sendCommandToDevice(name, binaryData);
1650     Assert.assertEquals(expectedResponse, actualResponse);
1651 
1652     List<String> actualRequests = mockService.getRequestPaths();
1653     Assert.assertEquals(1, actualRequests.size());
1654 
1655     String apiClientHeaderKey =
1656         mockService
1657             .getRequestHeaders()
1658             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1659             .iterator()
1660             .next();
1661     Assert.assertTrue(
1662         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1663             .matcher(apiClientHeaderKey)
1664             .matches());
1665   }
1666 
1667   @Test
sendCommandToDeviceExceptionTest()1668   public void sendCommandToDeviceExceptionTest() throws Exception {
1669     ApiException exception =
1670         ApiExceptionFactory.createException(
1671             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1672     mockService.addException(exception);
1673 
1674     try {
1675       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1676       ByteString binaryData = ByteString.EMPTY;
1677       client.sendCommandToDevice(name, binaryData);
1678       Assert.fail("No exception raised");
1679     } catch (InvalidArgumentException e) {
1680       // Expected exception.
1681     }
1682   }
1683 
1684   @Test
sendCommandToDeviceTest2()1685   public void sendCommandToDeviceTest2() throws Exception {
1686     SendCommandToDeviceResponse expectedResponse = SendCommandToDeviceResponse.newBuilder().build();
1687     mockService.addResponse(expectedResponse);
1688 
1689     String name =
1690         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1691     ByteString binaryData = ByteString.EMPTY;
1692 
1693     SendCommandToDeviceResponse actualResponse = client.sendCommandToDevice(name, binaryData);
1694     Assert.assertEquals(expectedResponse, actualResponse);
1695 
1696     List<String> actualRequests = mockService.getRequestPaths();
1697     Assert.assertEquals(1, actualRequests.size());
1698 
1699     String apiClientHeaderKey =
1700         mockService
1701             .getRequestHeaders()
1702             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1703             .iterator()
1704             .next();
1705     Assert.assertTrue(
1706         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1707             .matcher(apiClientHeaderKey)
1708             .matches());
1709   }
1710 
1711   @Test
sendCommandToDeviceExceptionTest2()1712   public void sendCommandToDeviceExceptionTest2() throws Exception {
1713     ApiException exception =
1714         ApiExceptionFactory.createException(
1715             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1716     mockService.addException(exception);
1717 
1718     try {
1719       String name =
1720           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1721       ByteString binaryData = ByteString.EMPTY;
1722       client.sendCommandToDevice(name, binaryData);
1723       Assert.fail("No exception raised");
1724     } catch (InvalidArgumentException e) {
1725       // Expected exception.
1726     }
1727   }
1728 
1729   @Test
sendCommandToDeviceTest3()1730   public void sendCommandToDeviceTest3() throws Exception {
1731     SendCommandToDeviceResponse expectedResponse = SendCommandToDeviceResponse.newBuilder().build();
1732     mockService.addResponse(expectedResponse);
1733 
1734     DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1735     ByteString binaryData = ByteString.EMPTY;
1736     String subfolder = "subfolder153561774";
1737 
1738     SendCommandToDeviceResponse actualResponse =
1739         client.sendCommandToDevice(name, binaryData, subfolder);
1740     Assert.assertEquals(expectedResponse, actualResponse);
1741 
1742     List<String> actualRequests = mockService.getRequestPaths();
1743     Assert.assertEquals(1, actualRequests.size());
1744 
1745     String apiClientHeaderKey =
1746         mockService
1747             .getRequestHeaders()
1748             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1749             .iterator()
1750             .next();
1751     Assert.assertTrue(
1752         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1753             .matcher(apiClientHeaderKey)
1754             .matches());
1755   }
1756 
1757   @Test
sendCommandToDeviceExceptionTest3()1758   public void sendCommandToDeviceExceptionTest3() throws Exception {
1759     ApiException exception =
1760         ApiExceptionFactory.createException(
1761             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1762     mockService.addException(exception);
1763 
1764     try {
1765       DeviceName name = DeviceName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]", "[DEVICE]");
1766       ByteString binaryData = ByteString.EMPTY;
1767       String subfolder = "subfolder153561774";
1768       client.sendCommandToDevice(name, binaryData, subfolder);
1769       Assert.fail("No exception raised");
1770     } catch (InvalidArgumentException e) {
1771       // Expected exception.
1772     }
1773   }
1774 
1775   @Test
sendCommandToDeviceTest4()1776   public void sendCommandToDeviceTest4() throws Exception {
1777     SendCommandToDeviceResponse expectedResponse = SendCommandToDeviceResponse.newBuilder().build();
1778     mockService.addResponse(expectedResponse);
1779 
1780     String name =
1781         "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1782     ByteString binaryData = ByteString.EMPTY;
1783     String subfolder = "subfolder153561774";
1784 
1785     SendCommandToDeviceResponse actualResponse =
1786         client.sendCommandToDevice(name, binaryData, subfolder);
1787     Assert.assertEquals(expectedResponse, actualResponse);
1788 
1789     List<String> actualRequests = mockService.getRequestPaths();
1790     Assert.assertEquals(1, actualRequests.size());
1791 
1792     String apiClientHeaderKey =
1793         mockService
1794             .getRequestHeaders()
1795             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1796             .iterator()
1797             .next();
1798     Assert.assertTrue(
1799         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1800             .matcher(apiClientHeaderKey)
1801             .matches());
1802   }
1803 
1804   @Test
sendCommandToDeviceExceptionTest4()1805   public void sendCommandToDeviceExceptionTest4() throws Exception {
1806     ApiException exception =
1807         ApiExceptionFactory.createException(
1808             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1809     mockService.addException(exception);
1810 
1811     try {
1812       String name =
1813           "projects/project-6436/locations/location-6436/registries/registrie-6436/devices/device-6436";
1814       ByteString binaryData = ByteString.EMPTY;
1815       String subfolder = "subfolder153561774";
1816       client.sendCommandToDevice(name, binaryData, subfolder);
1817       Assert.fail("No exception raised");
1818     } catch (InvalidArgumentException e) {
1819       // Expected exception.
1820     }
1821   }
1822 
1823   @Test
bindDeviceToGatewayTest()1824   public void bindDeviceToGatewayTest() throws Exception {
1825     BindDeviceToGatewayResponse expectedResponse = BindDeviceToGatewayResponse.newBuilder().build();
1826     mockService.addResponse(expectedResponse);
1827 
1828     RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1829     String gatewayId = "gatewayId-1354641793";
1830     String deviceId = "deviceId1109191185";
1831 
1832     BindDeviceToGatewayResponse actualResponse =
1833         client.bindDeviceToGateway(parent, gatewayId, deviceId);
1834     Assert.assertEquals(expectedResponse, actualResponse);
1835 
1836     List<String> actualRequests = mockService.getRequestPaths();
1837     Assert.assertEquals(1, actualRequests.size());
1838 
1839     String apiClientHeaderKey =
1840         mockService
1841             .getRequestHeaders()
1842             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1843             .iterator()
1844             .next();
1845     Assert.assertTrue(
1846         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1847             .matcher(apiClientHeaderKey)
1848             .matches());
1849   }
1850 
1851   @Test
bindDeviceToGatewayExceptionTest()1852   public void bindDeviceToGatewayExceptionTest() throws Exception {
1853     ApiException exception =
1854         ApiExceptionFactory.createException(
1855             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1856     mockService.addException(exception);
1857 
1858     try {
1859       RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1860       String gatewayId = "gatewayId-1354641793";
1861       String deviceId = "deviceId1109191185";
1862       client.bindDeviceToGateway(parent, gatewayId, deviceId);
1863       Assert.fail("No exception raised");
1864     } catch (InvalidArgumentException e) {
1865       // Expected exception.
1866     }
1867   }
1868 
1869   @Test
bindDeviceToGatewayTest2()1870   public void bindDeviceToGatewayTest2() throws Exception {
1871     BindDeviceToGatewayResponse expectedResponse = BindDeviceToGatewayResponse.newBuilder().build();
1872     mockService.addResponse(expectedResponse);
1873 
1874     String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
1875     String gatewayId = "gatewayId-1354641793";
1876     String deviceId = "deviceId1109191185";
1877 
1878     BindDeviceToGatewayResponse actualResponse =
1879         client.bindDeviceToGateway(parent, gatewayId, deviceId);
1880     Assert.assertEquals(expectedResponse, actualResponse);
1881 
1882     List<String> actualRequests = mockService.getRequestPaths();
1883     Assert.assertEquals(1, actualRequests.size());
1884 
1885     String apiClientHeaderKey =
1886         mockService
1887             .getRequestHeaders()
1888             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1889             .iterator()
1890             .next();
1891     Assert.assertTrue(
1892         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1893             .matcher(apiClientHeaderKey)
1894             .matches());
1895   }
1896 
1897   @Test
bindDeviceToGatewayExceptionTest2()1898   public void bindDeviceToGatewayExceptionTest2() throws Exception {
1899     ApiException exception =
1900         ApiExceptionFactory.createException(
1901             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1902     mockService.addException(exception);
1903 
1904     try {
1905       String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
1906       String gatewayId = "gatewayId-1354641793";
1907       String deviceId = "deviceId1109191185";
1908       client.bindDeviceToGateway(parent, gatewayId, deviceId);
1909       Assert.fail("No exception raised");
1910     } catch (InvalidArgumentException e) {
1911       // Expected exception.
1912     }
1913   }
1914 
1915   @Test
unbindDeviceFromGatewayTest()1916   public void unbindDeviceFromGatewayTest() throws Exception {
1917     UnbindDeviceFromGatewayResponse expectedResponse =
1918         UnbindDeviceFromGatewayResponse.newBuilder().build();
1919     mockService.addResponse(expectedResponse);
1920 
1921     RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1922     String gatewayId = "gatewayId-1354641793";
1923     String deviceId = "deviceId1109191185";
1924 
1925     UnbindDeviceFromGatewayResponse actualResponse =
1926         client.unbindDeviceFromGateway(parent, gatewayId, deviceId);
1927     Assert.assertEquals(expectedResponse, actualResponse);
1928 
1929     List<String> actualRequests = mockService.getRequestPaths();
1930     Assert.assertEquals(1, actualRequests.size());
1931 
1932     String apiClientHeaderKey =
1933         mockService
1934             .getRequestHeaders()
1935             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1936             .iterator()
1937             .next();
1938     Assert.assertTrue(
1939         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1940             .matcher(apiClientHeaderKey)
1941             .matches());
1942   }
1943 
1944   @Test
unbindDeviceFromGatewayExceptionTest()1945   public void unbindDeviceFromGatewayExceptionTest() throws Exception {
1946     ApiException exception =
1947         ApiExceptionFactory.createException(
1948             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1949     mockService.addException(exception);
1950 
1951     try {
1952       RegistryName parent = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]");
1953       String gatewayId = "gatewayId-1354641793";
1954       String deviceId = "deviceId1109191185";
1955       client.unbindDeviceFromGateway(parent, gatewayId, deviceId);
1956       Assert.fail("No exception raised");
1957     } catch (InvalidArgumentException e) {
1958       // Expected exception.
1959     }
1960   }
1961 
1962   @Test
unbindDeviceFromGatewayTest2()1963   public void unbindDeviceFromGatewayTest2() throws Exception {
1964     UnbindDeviceFromGatewayResponse expectedResponse =
1965         UnbindDeviceFromGatewayResponse.newBuilder().build();
1966     mockService.addResponse(expectedResponse);
1967 
1968     String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
1969     String gatewayId = "gatewayId-1354641793";
1970     String deviceId = "deviceId1109191185";
1971 
1972     UnbindDeviceFromGatewayResponse actualResponse =
1973         client.unbindDeviceFromGateway(parent, gatewayId, deviceId);
1974     Assert.assertEquals(expectedResponse, actualResponse);
1975 
1976     List<String> actualRequests = mockService.getRequestPaths();
1977     Assert.assertEquals(1, actualRequests.size());
1978 
1979     String apiClientHeaderKey =
1980         mockService
1981             .getRequestHeaders()
1982             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1983             .iterator()
1984             .next();
1985     Assert.assertTrue(
1986         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1987             .matcher(apiClientHeaderKey)
1988             .matches());
1989   }
1990 
1991   @Test
unbindDeviceFromGatewayExceptionTest2()1992   public void unbindDeviceFromGatewayExceptionTest2() throws Exception {
1993     ApiException exception =
1994         ApiExceptionFactory.createException(
1995             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1996     mockService.addException(exception);
1997 
1998     try {
1999       String parent = "projects/project-6316/locations/location-6316/registries/registrie-6316";
2000       String gatewayId = "gatewayId-1354641793";
2001       String deviceId = "deviceId1109191185";
2002       client.unbindDeviceFromGateway(parent, gatewayId, deviceId);
2003       Assert.fail("No exception raised");
2004     } catch (InvalidArgumentException e) {
2005       // Expected exception.
2006     }
2007   }
2008 }
2009