• 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.area120.tables.v1alpha;
18 
19 import static com.google.area120.tables.v1alpha.TablesServiceClient.ListRowsPagedResponse;
20 import static com.google.area120.tables.v1alpha.TablesServiceClient.ListTablesPagedResponse;
21 import static com.google.area120.tables.v1alpha.TablesServiceClient.ListWorkspacesPagedResponse;
22 
23 import com.google.api.gax.core.NoCredentialsProvider;
24 import com.google.api.gax.grpc.GaxGrpcProperties;
25 import com.google.api.gax.grpc.testing.LocalChannelProvider;
26 import com.google.api.gax.grpc.testing.MockGrpcService;
27 import com.google.api.gax.grpc.testing.MockServiceHelper;
28 import com.google.api.gax.rpc.ApiClientHeaderProvider;
29 import com.google.api.gax.rpc.InvalidArgumentException;
30 import com.google.area120.tables.v1alpha1.BatchCreateRowsRequest;
31 import com.google.area120.tables.v1alpha1.BatchCreateRowsResponse;
32 import com.google.area120.tables.v1alpha1.BatchDeleteRowsRequest;
33 import com.google.area120.tables.v1alpha1.BatchUpdateRowsRequest;
34 import com.google.area120.tables.v1alpha1.BatchUpdateRowsResponse;
35 import com.google.area120.tables.v1alpha1.ColumnDescription;
36 import com.google.area120.tables.v1alpha1.CreateRowRequest;
37 import com.google.area120.tables.v1alpha1.DeleteRowRequest;
38 import com.google.area120.tables.v1alpha1.GetRowRequest;
39 import com.google.area120.tables.v1alpha1.GetTableRequest;
40 import com.google.area120.tables.v1alpha1.GetWorkspaceRequest;
41 import com.google.area120.tables.v1alpha1.ListRowsRequest;
42 import com.google.area120.tables.v1alpha1.ListRowsResponse;
43 import com.google.area120.tables.v1alpha1.ListTablesRequest;
44 import com.google.area120.tables.v1alpha1.ListTablesResponse;
45 import com.google.area120.tables.v1alpha1.ListWorkspacesRequest;
46 import com.google.area120.tables.v1alpha1.ListWorkspacesResponse;
47 import com.google.area120.tables.v1alpha1.Row;
48 import com.google.area120.tables.v1alpha1.RowName;
49 import com.google.area120.tables.v1alpha1.Table;
50 import com.google.area120.tables.v1alpha1.TableName;
51 import com.google.area120.tables.v1alpha1.UpdateRowRequest;
52 import com.google.area120.tables.v1alpha1.Workspace;
53 import com.google.area120.tables.v1alpha1.WorkspaceName;
54 import com.google.common.collect.Lists;
55 import com.google.protobuf.AbstractMessage;
56 import com.google.protobuf.Empty;
57 import com.google.protobuf.FieldMask;
58 import com.google.protobuf.Value;
59 import io.grpc.StatusRuntimeException;
60 import java.io.IOException;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.HashMap;
64 import java.util.List;
65 import java.util.UUID;
66 import javax.annotation.Generated;
67 import org.junit.After;
68 import org.junit.AfterClass;
69 import org.junit.Assert;
70 import org.junit.Before;
71 import org.junit.BeforeClass;
72 import org.junit.Test;
73 
74 @Generated("by gapic-generator-java")
75 public class TablesServiceClientTest {
76   private static MockServiceHelper mockServiceHelper;
77   private static MockTablesService mockTablesService;
78   private LocalChannelProvider channelProvider;
79   private TablesServiceClient client;
80 
81   @BeforeClass
startStaticServer()82   public static void startStaticServer() {
83     mockTablesService = new MockTablesService();
84     mockServiceHelper =
85         new MockServiceHelper(
86             UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockTablesService));
87     mockServiceHelper.start();
88   }
89 
90   @AfterClass
stopServer()91   public static void stopServer() {
92     mockServiceHelper.stop();
93   }
94 
95   @Before
setUp()96   public void setUp() throws IOException {
97     mockServiceHelper.reset();
98     channelProvider = mockServiceHelper.createChannelProvider();
99     TablesServiceSettings settings =
100         TablesServiceSettings.newBuilder()
101             .setTransportChannelProvider(channelProvider)
102             .setCredentialsProvider(NoCredentialsProvider.create())
103             .build();
104     client = TablesServiceClient.create(settings);
105   }
106 
107   @After
tearDown()108   public void tearDown() throws Exception {
109     client.close();
110   }
111 
112   @Test
getTableTest()113   public void getTableTest() throws Exception {
114     Table expectedResponse =
115         Table.newBuilder()
116             .setName(TableName.of("[TABLE]").toString())
117             .setDisplayName("displayName1714148973")
118             .addAllColumns(new ArrayList<ColumnDescription>())
119             .build();
120     mockTablesService.addResponse(expectedResponse);
121 
122     TableName name = TableName.of("[TABLE]");
123 
124     Table actualResponse = client.getTable(name);
125     Assert.assertEquals(expectedResponse, actualResponse);
126 
127     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
128     Assert.assertEquals(1, actualRequests.size());
129     GetTableRequest actualRequest = ((GetTableRequest) actualRequests.get(0));
130 
131     Assert.assertEquals(name.toString(), actualRequest.getName());
132     Assert.assertTrue(
133         channelProvider.isHeaderSent(
134             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
135             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
136   }
137 
138   @Test
getTableExceptionTest()139   public void getTableExceptionTest() throws Exception {
140     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
141     mockTablesService.addException(exception);
142 
143     try {
144       TableName name = TableName.of("[TABLE]");
145       client.getTable(name);
146       Assert.fail("No exception raised");
147     } catch (InvalidArgumentException e) {
148       // Expected exception.
149     }
150   }
151 
152   @Test
getTableTest2()153   public void getTableTest2() throws Exception {
154     Table expectedResponse =
155         Table.newBuilder()
156             .setName(TableName.of("[TABLE]").toString())
157             .setDisplayName("displayName1714148973")
158             .addAllColumns(new ArrayList<ColumnDescription>())
159             .build();
160     mockTablesService.addResponse(expectedResponse);
161 
162     String name = "name3373707";
163 
164     Table actualResponse = client.getTable(name);
165     Assert.assertEquals(expectedResponse, actualResponse);
166 
167     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
168     Assert.assertEquals(1, actualRequests.size());
169     GetTableRequest actualRequest = ((GetTableRequest) actualRequests.get(0));
170 
171     Assert.assertEquals(name, actualRequest.getName());
172     Assert.assertTrue(
173         channelProvider.isHeaderSent(
174             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
175             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
176   }
177 
178   @Test
getTableExceptionTest2()179   public void getTableExceptionTest2() throws Exception {
180     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
181     mockTablesService.addException(exception);
182 
183     try {
184       String name = "name3373707";
185       client.getTable(name);
186       Assert.fail("No exception raised");
187     } catch (InvalidArgumentException e) {
188       // Expected exception.
189     }
190   }
191 
192   @Test
listTablesTest()193   public void listTablesTest() throws Exception {
194     Table responsesElement = Table.newBuilder().build();
195     ListTablesResponse expectedResponse =
196         ListTablesResponse.newBuilder()
197             .setNextPageToken("")
198             .addAllTables(Arrays.asList(responsesElement))
199             .build();
200     mockTablesService.addResponse(expectedResponse);
201 
202     ListTablesRequest request =
203         ListTablesRequest.newBuilder()
204             .setPageSize(883849137)
205             .setPageToken("pageToken873572522")
206             .build();
207 
208     ListTablesPagedResponse pagedListResponse = client.listTables(request);
209 
210     List<Table> resources = Lists.newArrayList(pagedListResponse.iterateAll());
211 
212     Assert.assertEquals(1, resources.size());
213     Assert.assertEquals(expectedResponse.getTablesList().get(0), resources.get(0));
214 
215     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
216     Assert.assertEquals(1, actualRequests.size());
217     ListTablesRequest actualRequest = ((ListTablesRequest) actualRequests.get(0));
218 
219     Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
220     Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
221     Assert.assertTrue(
222         channelProvider.isHeaderSent(
223             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
224             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
225   }
226 
227   @Test
listTablesExceptionTest()228   public void listTablesExceptionTest() throws Exception {
229     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
230     mockTablesService.addException(exception);
231 
232     try {
233       ListTablesRequest request =
234           ListTablesRequest.newBuilder()
235               .setPageSize(883849137)
236               .setPageToken("pageToken873572522")
237               .build();
238       client.listTables(request);
239       Assert.fail("No exception raised");
240     } catch (InvalidArgumentException e) {
241       // Expected exception.
242     }
243   }
244 
245   @Test
getWorkspaceTest()246   public void getWorkspaceTest() throws Exception {
247     Workspace expectedResponse =
248         Workspace.newBuilder()
249             .setName(WorkspaceName.of("[WORKSPACE]").toString())
250             .setDisplayName("displayName1714148973")
251             .addAllTables(new ArrayList<Table>())
252             .build();
253     mockTablesService.addResponse(expectedResponse);
254 
255     WorkspaceName name = WorkspaceName.of("[WORKSPACE]");
256 
257     Workspace actualResponse = client.getWorkspace(name);
258     Assert.assertEquals(expectedResponse, actualResponse);
259 
260     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
261     Assert.assertEquals(1, actualRequests.size());
262     GetWorkspaceRequest actualRequest = ((GetWorkspaceRequest) actualRequests.get(0));
263 
264     Assert.assertEquals(name.toString(), actualRequest.getName());
265     Assert.assertTrue(
266         channelProvider.isHeaderSent(
267             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
268             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
269   }
270 
271   @Test
getWorkspaceExceptionTest()272   public void getWorkspaceExceptionTest() throws Exception {
273     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
274     mockTablesService.addException(exception);
275 
276     try {
277       WorkspaceName name = WorkspaceName.of("[WORKSPACE]");
278       client.getWorkspace(name);
279       Assert.fail("No exception raised");
280     } catch (InvalidArgumentException e) {
281       // Expected exception.
282     }
283   }
284 
285   @Test
getWorkspaceTest2()286   public void getWorkspaceTest2() throws Exception {
287     Workspace expectedResponse =
288         Workspace.newBuilder()
289             .setName(WorkspaceName.of("[WORKSPACE]").toString())
290             .setDisplayName("displayName1714148973")
291             .addAllTables(new ArrayList<Table>())
292             .build();
293     mockTablesService.addResponse(expectedResponse);
294 
295     String name = "name3373707";
296 
297     Workspace actualResponse = client.getWorkspace(name);
298     Assert.assertEquals(expectedResponse, actualResponse);
299 
300     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
301     Assert.assertEquals(1, actualRequests.size());
302     GetWorkspaceRequest actualRequest = ((GetWorkspaceRequest) actualRequests.get(0));
303 
304     Assert.assertEquals(name, actualRequest.getName());
305     Assert.assertTrue(
306         channelProvider.isHeaderSent(
307             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
308             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
309   }
310 
311   @Test
getWorkspaceExceptionTest2()312   public void getWorkspaceExceptionTest2() throws Exception {
313     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
314     mockTablesService.addException(exception);
315 
316     try {
317       String name = "name3373707";
318       client.getWorkspace(name);
319       Assert.fail("No exception raised");
320     } catch (InvalidArgumentException e) {
321       // Expected exception.
322     }
323   }
324 
325   @Test
listWorkspacesTest()326   public void listWorkspacesTest() throws Exception {
327     Workspace responsesElement = Workspace.newBuilder().build();
328     ListWorkspacesResponse expectedResponse =
329         ListWorkspacesResponse.newBuilder()
330             .setNextPageToken("")
331             .addAllWorkspaces(Arrays.asList(responsesElement))
332             .build();
333     mockTablesService.addResponse(expectedResponse);
334 
335     ListWorkspacesRequest request =
336         ListWorkspacesRequest.newBuilder()
337             .setPageSize(883849137)
338             .setPageToken("pageToken873572522")
339             .build();
340 
341     ListWorkspacesPagedResponse pagedListResponse = client.listWorkspaces(request);
342 
343     List<Workspace> resources = Lists.newArrayList(pagedListResponse.iterateAll());
344 
345     Assert.assertEquals(1, resources.size());
346     Assert.assertEquals(expectedResponse.getWorkspacesList().get(0), resources.get(0));
347 
348     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
349     Assert.assertEquals(1, actualRequests.size());
350     ListWorkspacesRequest actualRequest = ((ListWorkspacesRequest) actualRequests.get(0));
351 
352     Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
353     Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
354     Assert.assertTrue(
355         channelProvider.isHeaderSent(
356             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
357             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
358   }
359 
360   @Test
listWorkspacesExceptionTest()361   public void listWorkspacesExceptionTest() throws Exception {
362     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
363     mockTablesService.addException(exception);
364 
365     try {
366       ListWorkspacesRequest request =
367           ListWorkspacesRequest.newBuilder()
368               .setPageSize(883849137)
369               .setPageToken("pageToken873572522")
370               .build();
371       client.listWorkspaces(request);
372       Assert.fail("No exception raised");
373     } catch (InvalidArgumentException e) {
374       // Expected exception.
375     }
376   }
377 
378   @Test
getRowTest()379   public void getRowTest() throws Exception {
380     Row expectedResponse =
381         Row.newBuilder()
382             .setName(RowName.of("[TABLE]", "[ROW]").toString())
383             .putAllValues(new HashMap<String, Value>())
384             .build();
385     mockTablesService.addResponse(expectedResponse);
386 
387     RowName name = RowName.of("[TABLE]", "[ROW]");
388 
389     Row actualResponse = client.getRow(name);
390     Assert.assertEquals(expectedResponse, actualResponse);
391 
392     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
393     Assert.assertEquals(1, actualRequests.size());
394     GetRowRequest actualRequest = ((GetRowRequest) actualRequests.get(0));
395 
396     Assert.assertEquals(name.toString(), actualRequest.getName());
397     Assert.assertTrue(
398         channelProvider.isHeaderSent(
399             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
400             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
401   }
402 
403   @Test
getRowExceptionTest()404   public void getRowExceptionTest() throws Exception {
405     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
406     mockTablesService.addException(exception);
407 
408     try {
409       RowName name = RowName.of("[TABLE]", "[ROW]");
410       client.getRow(name);
411       Assert.fail("No exception raised");
412     } catch (InvalidArgumentException e) {
413       // Expected exception.
414     }
415   }
416 
417   @Test
getRowTest2()418   public void getRowTest2() throws Exception {
419     Row expectedResponse =
420         Row.newBuilder()
421             .setName(RowName.of("[TABLE]", "[ROW]").toString())
422             .putAllValues(new HashMap<String, Value>())
423             .build();
424     mockTablesService.addResponse(expectedResponse);
425 
426     String name = "name3373707";
427 
428     Row actualResponse = client.getRow(name);
429     Assert.assertEquals(expectedResponse, actualResponse);
430 
431     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
432     Assert.assertEquals(1, actualRequests.size());
433     GetRowRequest actualRequest = ((GetRowRequest) actualRequests.get(0));
434 
435     Assert.assertEquals(name, actualRequest.getName());
436     Assert.assertTrue(
437         channelProvider.isHeaderSent(
438             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
439             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
440   }
441 
442   @Test
getRowExceptionTest2()443   public void getRowExceptionTest2() throws Exception {
444     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
445     mockTablesService.addException(exception);
446 
447     try {
448       String name = "name3373707";
449       client.getRow(name);
450       Assert.fail("No exception raised");
451     } catch (InvalidArgumentException e) {
452       // Expected exception.
453     }
454   }
455 
456   @Test
listRowsTest()457   public void listRowsTest() throws Exception {
458     Row responsesElement = Row.newBuilder().build();
459     ListRowsResponse expectedResponse =
460         ListRowsResponse.newBuilder()
461             .setNextPageToken("")
462             .addAllRows(Arrays.asList(responsesElement))
463             .build();
464     mockTablesService.addResponse(expectedResponse);
465 
466     String parent = "parent-995424086";
467 
468     ListRowsPagedResponse pagedListResponse = client.listRows(parent);
469 
470     List<Row> resources = Lists.newArrayList(pagedListResponse.iterateAll());
471 
472     Assert.assertEquals(1, resources.size());
473     Assert.assertEquals(expectedResponse.getRowsList().get(0), resources.get(0));
474 
475     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
476     Assert.assertEquals(1, actualRequests.size());
477     ListRowsRequest actualRequest = ((ListRowsRequest) actualRequests.get(0));
478 
479     Assert.assertEquals(parent, actualRequest.getParent());
480     Assert.assertTrue(
481         channelProvider.isHeaderSent(
482             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
483             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
484   }
485 
486   @Test
listRowsExceptionTest()487   public void listRowsExceptionTest() throws Exception {
488     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
489     mockTablesService.addException(exception);
490 
491     try {
492       String parent = "parent-995424086";
493       client.listRows(parent);
494       Assert.fail("No exception raised");
495     } catch (InvalidArgumentException e) {
496       // Expected exception.
497     }
498   }
499 
500   @Test
createRowTest()501   public void createRowTest() throws Exception {
502     Row expectedResponse =
503         Row.newBuilder()
504             .setName(RowName.of("[TABLE]", "[ROW]").toString())
505             .putAllValues(new HashMap<String, Value>())
506             .build();
507     mockTablesService.addResponse(expectedResponse);
508 
509     String parent = "parent-995424086";
510     Row row = Row.newBuilder().build();
511 
512     Row actualResponse = client.createRow(parent, row);
513     Assert.assertEquals(expectedResponse, actualResponse);
514 
515     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
516     Assert.assertEquals(1, actualRequests.size());
517     CreateRowRequest actualRequest = ((CreateRowRequest) actualRequests.get(0));
518 
519     Assert.assertEquals(parent, actualRequest.getParent());
520     Assert.assertEquals(row, actualRequest.getRow());
521     Assert.assertTrue(
522         channelProvider.isHeaderSent(
523             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
524             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
525   }
526 
527   @Test
createRowExceptionTest()528   public void createRowExceptionTest() throws Exception {
529     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
530     mockTablesService.addException(exception);
531 
532     try {
533       String parent = "parent-995424086";
534       Row row = Row.newBuilder().build();
535       client.createRow(parent, row);
536       Assert.fail("No exception raised");
537     } catch (InvalidArgumentException e) {
538       // Expected exception.
539     }
540   }
541 
542   @Test
batchCreateRowsTest()543   public void batchCreateRowsTest() throws Exception {
544     BatchCreateRowsResponse expectedResponse =
545         BatchCreateRowsResponse.newBuilder().addAllRows(new ArrayList<Row>()).build();
546     mockTablesService.addResponse(expectedResponse);
547 
548     BatchCreateRowsRequest request =
549         BatchCreateRowsRequest.newBuilder()
550             .setParent("parent-995424086")
551             .addAllRequests(new ArrayList<CreateRowRequest>())
552             .build();
553 
554     BatchCreateRowsResponse actualResponse = client.batchCreateRows(request);
555     Assert.assertEquals(expectedResponse, actualResponse);
556 
557     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
558     Assert.assertEquals(1, actualRequests.size());
559     BatchCreateRowsRequest actualRequest = ((BatchCreateRowsRequest) actualRequests.get(0));
560 
561     Assert.assertEquals(request.getParent(), actualRequest.getParent());
562     Assert.assertEquals(request.getRequestsList(), actualRequest.getRequestsList());
563     Assert.assertTrue(
564         channelProvider.isHeaderSent(
565             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
566             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
567   }
568 
569   @Test
batchCreateRowsExceptionTest()570   public void batchCreateRowsExceptionTest() throws Exception {
571     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
572     mockTablesService.addException(exception);
573 
574     try {
575       BatchCreateRowsRequest request =
576           BatchCreateRowsRequest.newBuilder()
577               .setParent("parent-995424086")
578               .addAllRequests(new ArrayList<CreateRowRequest>())
579               .build();
580       client.batchCreateRows(request);
581       Assert.fail("No exception raised");
582     } catch (InvalidArgumentException e) {
583       // Expected exception.
584     }
585   }
586 
587   @Test
updateRowTest()588   public void updateRowTest() throws Exception {
589     Row expectedResponse =
590         Row.newBuilder()
591             .setName(RowName.of("[TABLE]", "[ROW]").toString())
592             .putAllValues(new HashMap<String, Value>())
593             .build();
594     mockTablesService.addResponse(expectedResponse);
595 
596     Row row = Row.newBuilder().build();
597     FieldMask updateMask = FieldMask.newBuilder().build();
598 
599     Row actualResponse = client.updateRow(row, updateMask);
600     Assert.assertEquals(expectedResponse, actualResponse);
601 
602     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
603     Assert.assertEquals(1, actualRequests.size());
604     UpdateRowRequest actualRequest = ((UpdateRowRequest) actualRequests.get(0));
605 
606     Assert.assertEquals(row, actualRequest.getRow());
607     Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
608     Assert.assertTrue(
609         channelProvider.isHeaderSent(
610             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
611             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
612   }
613 
614   @Test
updateRowExceptionTest()615   public void updateRowExceptionTest() throws Exception {
616     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
617     mockTablesService.addException(exception);
618 
619     try {
620       Row row = Row.newBuilder().build();
621       FieldMask updateMask = FieldMask.newBuilder().build();
622       client.updateRow(row, updateMask);
623       Assert.fail("No exception raised");
624     } catch (InvalidArgumentException e) {
625       // Expected exception.
626     }
627   }
628 
629   @Test
batchUpdateRowsTest()630   public void batchUpdateRowsTest() throws Exception {
631     BatchUpdateRowsResponse expectedResponse =
632         BatchUpdateRowsResponse.newBuilder().addAllRows(new ArrayList<Row>()).build();
633     mockTablesService.addResponse(expectedResponse);
634 
635     BatchUpdateRowsRequest request =
636         BatchUpdateRowsRequest.newBuilder()
637             .setParent("parent-995424086")
638             .addAllRequests(new ArrayList<UpdateRowRequest>())
639             .build();
640 
641     BatchUpdateRowsResponse actualResponse = client.batchUpdateRows(request);
642     Assert.assertEquals(expectedResponse, actualResponse);
643 
644     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
645     Assert.assertEquals(1, actualRequests.size());
646     BatchUpdateRowsRequest actualRequest = ((BatchUpdateRowsRequest) actualRequests.get(0));
647 
648     Assert.assertEquals(request.getParent(), actualRequest.getParent());
649     Assert.assertEquals(request.getRequestsList(), actualRequest.getRequestsList());
650     Assert.assertTrue(
651         channelProvider.isHeaderSent(
652             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
653             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
654   }
655 
656   @Test
batchUpdateRowsExceptionTest()657   public void batchUpdateRowsExceptionTest() throws Exception {
658     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
659     mockTablesService.addException(exception);
660 
661     try {
662       BatchUpdateRowsRequest request =
663           BatchUpdateRowsRequest.newBuilder()
664               .setParent("parent-995424086")
665               .addAllRequests(new ArrayList<UpdateRowRequest>())
666               .build();
667       client.batchUpdateRows(request);
668       Assert.fail("No exception raised");
669     } catch (InvalidArgumentException e) {
670       // Expected exception.
671     }
672   }
673 
674   @Test
deleteRowTest()675   public void deleteRowTest() throws Exception {
676     Empty expectedResponse = Empty.newBuilder().build();
677     mockTablesService.addResponse(expectedResponse);
678 
679     RowName name = RowName.of("[TABLE]", "[ROW]");
680 
681     client.deleteRow(name);
682 
683     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
684     Assert.assertEquals(1, actualRequests.size());
685     DeleteRowRequest actualRequest = ((DeleteRowRequest) actualRequests.get(0));
686 
687     Assert.assertEquals(name.toString(), actualRequest.getName());
688     Assert.assertTrue(
689         channelProvider.isHeaderSent(
690             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
691             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
692   }
693 
694   @Test
deleteRowExceptionTest()695   public void deleteRowExceptionTest() throws Exception {
696     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
697     mockTablesService.addException(exception);
698 
699     try {
700       RowName name = RowName.of("[TABLE]", "[ROW]");
701       client.deleteRow(name);
702       Assert.fail("No exception raised");
703     } catch (InvalidArgumentException e) {
704       // Expected exception.
705     }
706   }
707 
708   @Test
deleteRowTest2()709   public void deleteRowTest2() throws Exception {
710     Empty expectedResponse = Empty.newBuilder().build();
711     mockTablesService.addResponse(expectedResponse);
712 
713     String name = "name3373707";
714 
715     client.deleteRow(name);
716 
717     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
718     Assert.assertEquals(1, actualRequests.size());
719     DeleteRowRequest actualRequest = ((DeleteRowRequest) actualRequests.get(0));
720 
721     Assert.assertEquals(name, actualRequest.getName());
722     Assert.assertTrue(
723         channelProvider.isHeaderSent(
724             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
725             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
726   }
727 
728   @Test
deleteRowExceptionTest2()729   public void deleteRowExceptionTest2() throws Exception {
730     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
731     mockTablesService.addException(exception);
732 
733     try {
734       String name = "name3373707";
735       client.deleteRow(name);
736       Assert.fail("No exception raised");
737     } catch (InvalidArgumentException e) {
738       // Expected exception.
739     }
740   }
741 
742   @Test
batchDeleteRowsTest()743   public void batchDeleteRowsTest() throws Exception {
744     Empty expectedResponse = Empty.newBuilder().build();
745     mockTablesService.addResponse(expectedResponse);
746 
747     BatchDeleteRowsRequest request =
748         BatchDeleteRowsRequest.newBuilder()
749             .setParent(TableName.of("[TABLE]").toString())
750             .addAllNames(new ArrayList<String>())
751             .build();
752 
753     client.batchDeleteRows(request);
754 
755     List<AbstractMessage> actualRequests = mockTablesService.getRequests();
756     Assert.assertEquals(1, actualRequests.size());
757     BatchDeleteRowsRequest actualRequest = ((BatchDeleteRowsRequest) actualRequests.get(0));
758 
759     Assert.assertEquals(request.getParent(), actualRequest.getParent());
760     Assert.assertEquals(request.getNamesList(), actualRequest.getNamesList());
761     Assert.assertTrue(
762         channelProvider.isHeaderSent(
763             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
764             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
765   }
766 
767   @Test
batchDeleteRowsExceptionTest()768   public void batchDeleteRowsExceptionTest() throws Exception {
769     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
770     mockTablesService.addException(exception);
771 
772     try {
773       BatchDeleteRowsRequest request =
774           BatchDeleteRowsRequest.newBuilder()
775               .setParent(TableName.of("[TABLE]").toString())
776               .addAllNames(new ArrayList<String>())
777               .build();
778       client.batchDeleteRows(request);
779       Assert.fail("No exception raised");
780     } catch (InvalidArgumentException e) {
781       // Expected exception.
782     }
783   }
784 }
785