• 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.gaming.v1beta;
18 
19 import static com.google.cloud.gaming.v1beta.GameServerClustersServiceClient.ListGameServerClustersPagedResponse;
20 
21 import com.google.api.gax.core.NoCredentialsProvider;
22 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
23 import com.google.api.gax.httpjson.testing.MockHttpService;
24 import com.google.api.gax.rpc.ApiClientHeaderProvider;
25 import com.google.api.gax.rpc.ApiException;
26 import com.google.api.gax.rpc.ApiExceptionFactory;
27 import com.google.api.gax.rpc.InvalidArgumentException;
28 import com.google.api.gax.rpc.StatusCode;
29 import com.google.api.gax.rpc.testing.FakeStatusCode;
30 import com.google.cloud.gaming.v1beta.stub.HttpJsonGameServerClustersServiceStub;
31 import com.google.common.collect.Lists;
32 import com.google.longrunning.Operation;
33 import com.google.protobuf.Any;
34 import com.google.protobuf.Empty;
35 import com.google.protobuf.FieldMask;
36 import com.google.protobuf.Timestamp;
37 import java.io.IOException;
38 import java.util.Arrays;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.concurrent.ExecutionException;
42 import javax.annotation.Generated;
43 import org.junit.After;
44 import org.junit.AfterClass;
45 import org.junit.Assert;
46 import org.junit.Before;
47 import org.junit.BeforeClass;
48 import org.junit.Test;
49 
50 @Generated("by gapic-generator-java")
51 public class GameServerClustersServiceClientHttpJsonTest {
52   private static MockHttpService mockService;
53   private static GameServerClustersServiceClient client;
54 
55   @BeforeClass
startStaticServer()56   public static void startStaticServer() throws IOException {
57     mockService =
58         new MockHttpService(
59             HttpJsonGameServerClustersServiceStub.getMethodDescriptors(),
60             GameServerClustersServiceSettings.getDefaultEndpoint());
61     GameServerClustersServiceSettings settings =
62         GameServerClustersServiceSettings.newHttpJsonBuilder()
63             .setTransportChannelProvider(
64                 GameServerClustersServiceSettings.defaultHttpJsonTransportProviderBuilder()
65                     .setHttpTransport(mockService)
66                     .build())
67             .setCredentialsProvider(NoCredentialsProvider.create())
68             .build();
69     client = GameServerClustersServiceClient.create(settings);
70   }
71 
72   @AfterClass
stopServer()73   public static void stopServer() {
74     client.close();
75   }
76 
77   @Before
setUp()78   public void setUp() {}
79 
80   @After
tearDown()81   public void tearDown() throws Exception {
82     mockService.reset();
83   }
84 
85   @Test
listGameServerClustersTest()86   public void listGameServerClustersTest() throws Exception {
87     GameServerCluster responsesElement = GameServerCluster.newBuilder().build();
88     ListGameServerClustersResponse expectedResponse =
89         ListGameServerClustersResponse.newBuilder()
90             .setNextPageToken("")
91             .addAllGameServerClusters(Arrays.asList(responsesElement))
92             .build();
93     mockService.addResponse(expectedResponse);
94 
95     RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]");
96 
97     ListGameServerClustersPagedResponse pagedListResponse = client.listGameServerClusters(parent);
98 
99     List<GameServerCluster> resources = Lists.newArrayList(pagedListResponse.iterateAll());
100 
101     Assert.assertEquals(1, resources.size());
102     Assert.assertEquals(expectedResponse.getGameServerClustersList().get(0), resources.get(0));
103 
104     List<String> actualRequests = mockService.getRequestPaths();
105     Assert.assertEquals(1, actualRequests.size());
106 
107     String apiClientHeaderKey =
108         mockService
109             .getRequestHeaders()
110             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
111             .iterator()
112             .next();
113     Assert.assertTrue(
114         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
115             .matcher(apiClientHeaderKey)
116             .matches());
117   }
118 
119   @Test
listGameServerClustersExceptionTest()120   public void listGameServerClustersExceptionTest() throws Exception {
121     ApiException exception =
122         ApiExceptionFactory.createException(
123             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
124     mockService.addException(exception);
125 
126     try {
127       RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]");
128       client.listGameServerClusters(parent);
129       Assert.fail("No exception raised");
130     } catch (InvalidArgumentException e) {
131       // Expected exception.
132     }
133   }
134 
135   @Test
listGameServerClustersTest2()136   public void listGameServerClustersTest2() throws Exception {
137     GameServerCluster responsesElement = GameServerCluster.newBuilder().build();
138     ListGameServerClustersResponse expectedResponse =
139         ListGameServerClustersResponse.newBuilder()
140             .setNextPageToken("")
141             .addAllGameServerClusters(Arrays.asList(responsesElement))
142             .build();
143     mockService.addResponse(expectedResponse);
144 
145     String parent = "projects/project-3755/locations/location-3755/realms/realm-3755";
146 
147     ListGameServerClustersPagedResponse pagedListResponse = client.listGameServerClusters(parent);
148 
149     List<GameServerCluster> resources = Lists.newArrayList(pagedListResponse.iterateAll());
150 
151     Assert.assertEquals(1, resources.size());
152     Assert.assertEquals(expectedResponse.getGameServerClustersList().get(0), resources.get(0));
153 
154     List<String> actualRequests = mockService.getRequestPaths();
155     Assert.assertEquals(1, actualRequests.size());
156 
157     String apiClientHeaderKey =
158         mockService
159             .getRequestHeaders()
160             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
161             .iterator()
162             .next();
163     Assert.assertTrue(
164         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
165             .matcher(apiClientHeaderKey)
166             .matches());
167   }
168 
169   @Test
listGameServerClustersExceptionTest2()170   public void listGameServerClustersExceptionTest2() throws Exception {
171     ApiException exception =
172         ApiExceptionFactory.createException(
173             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
174     mockService.addException(exception);
175 
176     try {
177       String parent = "projects/project-3755/locations/location-3755/realms/realm-3755";
178       client.listGameServerClusters(parent);
179       Assert.fail("No exception raised");
180     } catch (InvalidArgumentException e) {
181       // Expected exception.
182     }
183   }
184 
185   @Test
getGameServerClusterTest()186   public void getGameServerClusterTest() throws Exception {
187     GameServerCluster expectedResponse =
188         GameServerCluster.newBuilder()
189             .setName(
190                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
191                     .toString())
192             .setCreateTime(Timestamp.newBuilder().build())
193             .setUpdateTime(Timestamp.newBuilder().build())
194             .putAllLabels(new HashMap<String, String>())
195             .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
196             .setEtag("etag3123477")
197             .setDescription("description-1724546052")
198             .build();
199     mockService.addResponse(expectedResponse);
200 
201     GameServerClusterName name =
202         GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]");
203 
204     GameServerCluster actualResponse = client.getGameServerCluster(name);
205     Assert.assertEquals(expectedResponse, actualResponse);
206 
207     List<String> actualRequests = mockService.getRequestPaths();
208     Assert.assertEquals(1, actualRequests.size());
209 
210     String apiClientHeaderKey =
211         mockService
212             .getRequestHeaders()
213             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
214             .iterator()
215             .next();
216     Assert.assertTrue(
217         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
218             .matcher(apiClientHeaderKey)
219             .matches());
220   }
221 
222   @Test
getGameServerClusterExceptionTest()223   public void getGameServerClusterExceptionTest() throws Exception {
224     ApiException exception =
225         ApiExceptionFactory.createException(
226             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
227     mockService.addException(exception);
228 
229     try {
230       GameServerClusterName name =
231           GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]");
232       client.getGameServerCluster(name);
233       Assert.fail("No exception raised");
234     } catch (InvalidArgumentException e) {
235       // Expected exception.
236     }
237   }
238 
239   @Test
getGameServerClusterTest2()240   public void getGameServerClusterTest2() throws Exception {
241     GameServerCluster expectedResponse =
242         GameServerCluster.newBuilder()
243             .setName(
244                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
245                     .toString())
246             .setCreateTime(Timestamp.newBuilder().build())
247             .setUpdateTime(Timestamp.newBuilder().build())
248             .putAllLabels(new HashMap<String, String>())
249             .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
250             .setEtag("etag3123477")
251             .setDescription("description-1724546052")
252             .build();
253     mockService.addResponse(expectedResponse);
254 
255     String name =
256         "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532";
257 
258     GameServerCluster actualResponse = client.getGameServerCluster(name);
259     Assert.assertEquals(expectedResponse, actualResponse);
260 
261     List<String> actualRequests = mockService.getRequestPaths();
262     Assert.assertEquals(1, actualRequests.size());
263 
264     String apiClientHeaderKey =
265         mockService
266             .getRequestHeaders()
267             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
268             .iterator()
269             .next();
270     Assert.assertTrue(
271         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
272             .matcher(apiClientHeaderKey)
273             .matches());
274   }
275 
276   @Test
getGameServerClusterExceptionTest2()277   public void getGameServerClusterExceptionTest2() throws Exception {
278     ApiException exception =
279         ApiExceptionFactory.createException(
280             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
281     mockService.addException(exception);
282 
283     try {
284       String name =
285           "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532";
286       client.getGameServerCluster(name);
287       Assert.fail("No exception raised");
288     } catch (InvalidArgumentException e) {
289       // Expected exception.
290     }
291   }
292 
293   @Test
createGameServerClusterTest()294   public void createGameServerClusterTest() throws Exception {
295     GameServerCluster expectedResponse =
296         GameServerCluster.newBuilder()
297             .setName(
298                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
299                     .toString())
300             .setCreateTime(Timestamp.newBuilder().build())
301             .setUpdateTime(Timestamp.newBuilder().build())
302             .putAllLabels(new HashMap<String, String>())
303             .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
304             .setEtag("etag3123477")
305             .setDescription("description-1724546052")
306             .build();
307     Operation resultOperation =
308         Operation.newBuilder()
309             .setName("createGameServerClusterTest")
310             .setDone(true)
311             .setResponse(Any.pack(expectedResponse))
312             .build();
313     mockService.addResponse(resultOperation);
314 
315     RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]");
316     GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build();
317     String gameServerClusterId = "gameServerClusterId-1301104032";
318 
319     GameServerCluster actualResponse =
320         client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get();
321     Assert.assertEquals(expectedResponse, actualResponse);
322 
323     List<String> actualRequests = mockService.getRequestPaths();
324     Assert.assertEquals(1, actualRequests.size());
325 
326     String apiClientHeaderKey =
327         mockService
328             .getRequestHeaders()
329             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
330             .iterator()
331             .next();
332     Assert.assertTrue(
333         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
334             .matcher(apiClientHeaderKey)
335             .matches());
336   }
337 
338   @Test
createGameServerClusterExceptionTest()339   public void createGameServerClusterExceptionTest() throws Exception {
340     ApiException exception =
341         ApiExceptionFactory.createException(
342             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
343     mockService.addException(exception);
344 
345     try {
346       RealmName parent = RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]");
347       GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build();
348       String gameServerClusterId = "gameServerClusterId-1301104032";
349       client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get();
350       Assert.fail("No exception raised");
351     } catch (ExecutionException e) {
352     }
353   }
354 
355   @Test
createGameServerClusterTest2()356   public void createGameServerClusterTest2() throws Exception {
357     GameServerCluster expectedResponse =
358         GameServerCluster.newBuilder()
359             .setName(
360                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
361                     .toString())
362             .setCreateTime(Timestamp.newBuilder().build())
363             .setUpdateTime(Timestamp.newBuilder().build())
364             .putAllLabels(new HashMap<String, String>())
365             .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
366             .setEtag("etag3123477")
367             .setDescription("description-1724546052")
368             .build();
369     Operation resultOperation =
370         Operation.newBuilder()
371             .setName("createGameServerClusterTest")
372             .setDone(true)
373             .setResponse(Any.pack(expectedResponse))
374             .build();
375     mockService.addResponse(resultOperation);
376 
377     String parent = "projects/project-3755/locations/location-3755/realms/realm-3755";
378     GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build();
379     String gameServerClusterId = "gameServerClusterId-1301104032";
380 
381     GameServerCluster actualResponse =
382         client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get();
383     Assert.assertEquals(expectedResponse, actualResponse);
384 
385     List<String> actualRequests = mockService.getRequestPaths();
386     Assert.assertEquals(1, actualRequests.size());
387 
388     String apiClientHeaderKey =
389         mockService
390             .getRequestHeaders()
391             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
392             .iterator()
393             .next();
394     Assert.assertTrue(
395         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
396             .matcher(apiClientHeaderKey)
397             .matches());
398   }
399 
400   @Test
createGameServerClusterExceptionTest2()401   public void createGameServerClusterExceptionTest2() throws Exception {
402     ApiException exception =
403         ApiExceptionFactory.createException(
404             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
405     mockService.addException(exception);
406 
407     try {
408       String parent = "projects/project-3755/locations/location-3755/realms/realm-3755";
409       GameServerCluster gameServerCluster = GameServerCluster.newBuilder().build();
410       String gameServerClusterId = "gameServerClusterId-1301104032";
411       client.createGameServerClusterAsync(parent, gameServerCluster, gameServerClusterId).get();
412       Assert.fail("No exception raised");
413     } catch (ExecutionException e) {
414     }
415   }
416 
417   @Test
previewCreateGameServerClusterTest()418   public void previewCreateGameServerClusterTest() throws Exception {
419     PreviewCreateGameServerClusterResponse expectedResponse =
420         PreviewCreateGameServerClusterResponse.newBuilder()
421             .setEtag("etag3123477")
422             .setTargetState(TargetState.newBuilder().build())
423             .build();
424     mockService.addResponse(expectedResponse);
425 
426     PreviewCreateGameServerClusterRequest request =
427         PreviewCreateGameServerClusterRequest.newBuilder()
428             .setParent(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString())
429             .setGameServerClusterId("gameServerClusterId-1301104032")
430             .setGameServerCluster(GameServerCluster.newBuilder().build())
431             .setPreviewTime(Timestamp.newBuilder().build())
432             .build();
433 
434     PreviewCreateGameServerClusterResponse actualResponse =
435         client.previewCreateGameServerCluster(request);
436     Assert.assertEquals(expectedResponse, actualResponse);
437 
438     List<String> actualRequests = mockService.getRequestPaths();
439     Assert.assertEquals(1, actualRequests.size());
440 
441     String apiClientHeaderKey =
442         mockService
443             .getRequestHeaders()
444             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
445             .iterator()
446             .next();
447     Assert.assertTrue(
448         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
449             .matcher(apiClientHeaderKey)
450             .matches());
451   }
452 
453   @Test
previewCreateGameServerClusterExceptionTest()454   public void previewCreateGameServerClusterExceptionTest() throws Exception {
455     ApiException exception =
456         ApiExceptionFactory.createException(
457             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
458     mockService.addException(exception);
459 
460     try {
461       PreviewCreateGameServerClusterRequest request =
462           PreviewCreateGameServerClusterRequest.newBuilder()
463               .setParent(RealmName.of("[PROJECT]", "[LOCATION]", "[REALM]").toString())
464               .setGameServerClusterId("gameServerClusterId-1301104032")
465               .setGameServerCluster(GameServerCluster.newBuilder().build())
466               .setPreviewTime(Timestamp.newBuilder().build())
467               .build();
468       client.previewCreateGameServerCluster(request);
469       Assert.fail("No exception raised");
470     } catch (InvalidArgumentException e) {
471       // Expected exception.
472     }
473   }
474 
475   @Test
deleteGameServerClusterTest()476   public void deleteGameServerClusterTest() throws Exception {
477     Empty expectedResponse = Empty.newBuilder().build();
478     Operation resultOperation =
479         Operation.newBuilder()
480             .setName("deleteGameServerClusterTest")
481             .setDone(true)
482             .setResponse(Any.pack(expectedResponse))
483             .build();
484     mockService.addResponse(resultOperation);
485 
486     GameServerClusterName name =
487         GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]");
488 
489     client.deleteGameServerClusterAsync(name).get();
490 
491     List<String> actualRequests = mockService.getRequestPaths();
492     Assert.assertEquals(1, actualRequests.size());
493 
494     String apiClientHeaderKey =
495         mockService
496             .getRequestHeaders()
497             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
498             .iterator()
499             .next();
500     Assert.assertTrue(
501         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
502             .matcher(apiClientHeaderKey)
503             .matches());
504   }
505 
506   @Test
deleteGameServerClusterExceptionTest()507   public void deleteGameServerClusterExceptionTest() throws Exception {
508     ApiException exception =
509         ApiExceptionFactory.createException(
510             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
511     mockService.addException(exception);
512 
513     try {
514       GameServerClusterName name =
515           GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]");
516       client.deleteGameServerClusterAsync(name).get();
517       Assert.fail("No exception raised");
518     } catch (ExecutionException e) {
519     }
520   }
521 
522   @Test
deleteGameServerClusterTest2()523   public void deleteGameServerClusterTest2() throws Exception {
524     Empty expectedResponse = Empty.newBuilder().build();
525     Operation resultOperation =
526         Operation.newBuilder()
527             .setName("deleteGameServerClusterTest")
528             .setDone(true)
529             .setResponse(Any.pack(expectedResponse))
530             .build();
531     mockService.addResponse(resultOperation);
532 
533     String name =
534         "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532";
535 
536     client.deleteGameServerClusterAsync(name).get();
537 
538     List<String> actualRequests = mockService.getRequestPaths();
539     Assert.assertEquals(1, actualRequests.size());
540 
541     String apiClientHeaderKey =
542         mockService
543             .getRequestHeaders()
544             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
545             .iterator()
546             .next();
547     Assert.assertTrue(
548         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
549             .matcher(apiClientHeaderKey)
550             .matches());
551   }
552 
553   @Test
deleteGameServerClusterExceptionTest2()554   public void deleteGameServerClusterExceptionTest2() throws Exception {
555     ApiException exception =
556         ApiExceptionFactory.createException(
557             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
558     mockService.addException(exception);
559 
560     try {
561       String name =
562           "projects/project-4532/locations/location-4532/realms/realm-4532/gameServerClusters/gameServerCluster-4532";
563       client.deleteGameServerClusterAsync(name).get();
564       Assert.fail("No exception raised");
565     } catch (ExecutionException e) {
566     }
567   }
568 
569   @Test
previewDeleteGameServerClusterTest()570   public void previewDeleteGameServerClusterTest() throws Exception {
571     PreviewDeleteGameServerClusterResponse expectedResponse =
572         PreviewDeleteGameServerClusterResponse.newBuilder()
573             .setEtag("etag3123477")
574             .setTargetState(TargetState.newBuilder().build())
575             .build();
576     mockService.addResponse(expectedResponse);
577 
578     PreviewDeleteGameServerClusterRequest request =
579         PreviewDeleteGameServerClusterRequest.newBuilder()
580             .setName(
581                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
582                     .toString())
583             .setPreviewTime(Timestamp.newBuilder().build())
584             .build();
585 
586     PreviewDeleteGameServerClusterResponse actualResponse =
587         client.previewDeleteGameServerCluster(request);
588     Assert.assertEquals(expectedResponse, actualResponse);
589 
590     List<String> actualRequests = mockService.getRequestPaths();
591     Assert.assertEquals(1, actualRequests.size());
592 
593     String apiClientHeaderKey =
594         mockService
595             .getRequestHeaders()
596             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
597             .iterator()
598             .next();
599     Assert.assertTrue(
600         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
601             .matcher(apiClientHeaderKey)
602             .matches());
603   }
604 
605   @Test
previewDeleteGameServerClusterExceptionTest()606   public void previewDeleteGameServerClusterExceptionTest() throws Exception {
607     ApiException exception =
608         ApiExceptionFactory.createException(
609             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
610     mockService.addException(exception);
611 
612     try {
613       PreviewDeleteGameServerClusterRequest request =
614           PreviewDeleteGameServerClusterRequest.newBuilder()
615               .setName(
616                   GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
617                       .toString())
618               .setPreviewTime(Timestamp.newBuilder().build())
619               .build();
620       client.previewDeleteGameServerCluster(request);
621       Assert.fail("No exception raised");
622     } catch (InvalidArgumentException e) {
623       // Expected exception.
624     }
625   }
626 
627   @Test
updateGameServerClusterTest()628   public void updateGameServerClusterTest() throws Exception {
629     GameServerCluster expectedResponse =
630         GameServerCluster.newBuilder()
631             .setName(
632                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
633                     .toString())
634             .setCreateTime(Timestamp.newBuilder().build())
635             .setUpdateTime(Timestamp.newBuilder().build())
636             .putAllLabels(new HashMap<String, String>())
637             .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
638             .setEtag("etag3123477")
639             .setDescription("description-1724546052")
640             .build();
641     Operation resultOperation =
642         Operation.newBuilder()
643             .setName("updateGameServerClusterTest")
644             .setDone(true)
645             .setResponse(Any.pack(expectedResponse))
646             .build();
647     mockService.addResponse(resultOperation);
648 
649     GameServerCluster gameServerCluster =
650         GameServerCluster.newBuilder()
651             .setName(
652                 GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
653                     .toString())
654             .setCreateTime(Timestamp.newBuilder().build())
655             .setUpdateTime(Timestamp.newBuilder().build())
656             .putAllLabels(new HashMap<String, String>())
657             .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
658             .setEtag("etag3123477")
659             .setDescription("description-1724546052")
660             .build();
661     FieldMask updateMask = FieldMask.newBuilder().build();
662 
663     GameServerCluster actualResponse =
664         client.updateGameServerClusterAsync(gameServerCluster, updateMask).get();
665     Assert.assertEquals(expectedResponse, actualResponse);
666 
667     List<String> actualRequests = mockService.getRequestPaths();
668     Assert.assertEquals(1, actualRequests.size());
669 
670     String apiClientHeaderKey =
671         mockService
672             .getRequestHeaders()
673             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
674             .iterator()
675             .next();
676     Assert.assertTrue(
677         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
678             .matcher(apiClientHeaderKey)
679             .matches());
680   }
681 
682   @Test
updateGameServerClusterExceptionTest()683   public void updateGameServerClusterExceptionTest() throws Exception {
684     ApiException exception =
685         ApiExceptionFactory.createException(
686             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
687     mockService.addException(exception);
688 
689     try {
690       GameServerCluster gameServerCluster =
691           GameServerCluster.newBuilder()
692               .setName(
693                   GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
694                       .toString())
695               .setCreateTime(Timestamp.newBuilder().build())
696               .setUpdateTime(Timestamp.newBuilder().build())
697               .putAllLabels(new HashMap<String, String>())
698               .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
699               .setEtag("etag3123477")
700               .setDescription("description-1724546052")
701               .build();
702       FieldMask updateMask = FieldMask.newBuilder().build();
703       client.updateGameServerClusterAsync(gameServerCluster, updateMask).get();
704       Assert.fail("No exception raised");
705     } catch (ExecutionException e) {
706     }
707   }
708 
709   @Test
previewUpdateGameServerClusterTest()710   public void previewUpdateGameServerClusterTest() throws Exception {
711     PreviewUpdateGameServerClusterResponse expectedResponse =
712         PreviewUpdateGameServerClusterResponse.newBuilder()
713             .setEtag("etag3123477")
714             .setTargetState(TargetState.newBuilder().build())
715             .build();
716     mockService.addResponse(expectedResponse);
717 
718     PreviewUpdateGameServerClusterRequest request =
719         PreviewUpdateGameServerClusterRequest.newBuilder()
720             .setGameServerCluster(
721                 GameServerCluster.newBuilder()
722                     .setName(
723                         GameServerClusterName.of("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
724                             .toString())
725                     .setCreateTime(Timestamp.newBuilder().build())
726                     .setUpdateTime(Timestamp.newBuilder().build())
727                     .putAllLabels(new HashMap<String, String>())
728                     .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
729                     .setEtag("etag3123477")
730                     .setDescription("description-1724546052")
731                     .build())
732             .setUpdateMask(FieldMask.newBuilder().build())
733             .setPreviewTime(Timestamp.newBuilder().build())
734             .build();
735 
736     PreviewUpdateGameServerClusterResponse actualResponse =
737         client.previewUpdateGameServerCluster(request);
738     Assert.assertEquals(expectedResponse, actualResponse);
739 
740     List<String> actualRequests = mockService.getRequestPaths();
741     Assert.assertEquals(1, actualRequests.size());
742 
743     String apiClientHeaderKey =
744         mockService
745             .getRequestHeaders()
746             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
747             .iterator()
748             .next();
749     Assert.assertTrue(
750         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
751             .matcher(apiClientHeaderKey)
752             .matches());
753   }
754 
755   @Test
previewUpdateGameServerClusterExceptionTest()756   public void previewUpdateGameServerClusterExceptionTest() throws Exception {
757     ApiException exception =
758         ApiExceptionFactory.createException(
759             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
760     mockService.addException(exception);
761 
762     try {
763       PreviewUpdateGameServerClusterRequest request =
764           PreviewUpdateGameServerClusterRequest.newBuilder()
765               .setGameServerCluster(
766                   GameServerCluster.newBuilder()
767                       .setName(
768                           GameServerClusterName.of(
769                                   "[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]")
770                               .toString())
771                       .setCreateTime(Timestamp.newBuilder().build())
772                       .setUpdateTime(Timestamp.newBuilder().build())
773                       .putAllLabels(new HashMap<String, String>())
774                       .setConnectionInfo(GameServerClusterConnectionInfo.newBuilder().build())
775                       .setEtag("etag3123477")
776                       .setDescription("description-1724546052")
777                       .build())
778               .setUpdateMask(FieldMask.newBuilder().build())
779               .setPreviewTime(Timestamp.newBuilder().build())
780               .build();
781       client.previewUpdateGameServerCluster(request);
782       Assert.fail("No exception raised");
783     } catch (InvalidArgumentException e) {
784       // Expected exception.
785     }
786   }
787 }
788