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