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.retail.v2; 18 19 import static com.google.cloud.retail.v2.CatalogServiceClient.ListCatalogsPagedResponse; 20 21 import com.google.api.gax.core.NoCredentialsProvider; 22 import com.google.api.gax.grpc.GaxGrpcProperties; 23 import com.google.api.gax.grpc.testing.LocalChannelProvider; 24 import com.google.api.gax.grpc.testing.MockGrpcService; 25 import com.google.api.gax.grpc.testing.MockServiceHelper; 26 import com.google.api.gax.rpc.ApiClientHeaderProvider; 27 import com.google.api.gax.rpc.InvalidArgumentException; 28 import com.google.common.collect.Lists; 29 import com.google.protobuf.AbstractMessage; 30 import com.google.protobuf.Empty; 31 import com.google.protobuf.FieldMask; 32 import com.google.protobuf.Timestamp; 33 import io.grpc.StatusRuntimeException; 34 import java.io.IOException; 35 import java.util.Arrays; 36 import java.util.HashMap; 37 import java.util.List; 38 import java.util.UUID; 39 import javax.annotation.Generated; 40 import org.junit.After; 41 import org.junit.AfterClass; 42 import org.junit.Assert; 43 import org.junit.Before; 44 import org.junit.BeforeClass; 45 import org.junit.Test; 46 47 @Generated("by gapic-generator-java") 48 public class CatalogServiceClientTest { 49 private static MockCatalogService mockCatalogService; 50 private static MockServiceHelper mockServiceHelper; 51 private LocalChannelProvider channelProvider; 52 private CatalogServiceClient client; 53 54 @BeforeClass startStaticServer()55 public static void startStaticServer() { 56 mockCatalogService = new MockCatalogService(); 57 mockServiceHelper = 58 new MockServiceHelper( 59 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockCatalogService)); 60 mockServiceHelper.start(); 61 } 62 63 @AfterClass stopServer()64 public static void stopServer() { 65 mockServiceHelper.stop(); 66 } 67 68 @Before setUp()69 public void setUp() throws IOException { 70 mockServiceHelper.reset(); 71 channelProvider = mockServiceHelper.createChannelProvider(); 72 CatalogServiceSettings settings = 73 CatalogServiceSettings.newBuilder() 74 .setTransportChannelProvider(channelProvider) 75 .setCredentialsProvider(NoCredentialsProvider.create()) 76 .build(); 77 client = CatalogServiceClient.create(settings); 78 } 79 80 @After tearDown()81 public void tearDown() throws Exception { 82 client.close(); 83 } 84 85 @Test listCatalogsTest()86 public void listCatalogsTest() throws Exception { 87 Catalog responsesElement = Catalog.newBuilder().build(); 88 ListCatalogsResponse expectedResponse = 89 ListCatalogsResponse.newBuilder() 90 .setNextPageToken("") 91 .addAllCatalogs(Arrays.asList(responsesElement)) 92 .build(); 93 mockCatalogService.addResponse(expectedResponse); 94 95 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 96 97 ListCatalogsPagedResponse pagedListResponse = client.listCatalogs(parent); 98 99 List<Catalog> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 100 101 Assert.assertEquals(1, resources.size()); 102 Assert.assertEquals(expectedResponse.getCatalogsList().get(0), resources.get(0)); 103 104 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 105 Assert.assertEquals(1, actualRequests.size()); 106 ListCatalogsRequest actualRequest = ((ListCatalogsRequest) actualRequests.get(0)); 107 108 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 109 Assert.assertTrue( 110 channelProvider.isHeaderSent( 111 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 112 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 113 } 114 115 @Test listCatalogsExceptionTest()116 public void listCatalogsExceptionTest() throws Exception { 117 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 118 mockCatalogService.addException(exception); 119 120 try { 121 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 122 client.listCatalogs(parent); 123 Assert.fail("No exception raised"); 124 } catch (InvalidArgumentException e) { 125 // Expected exception. 126 } 127 } 128 129 @Test listCatalogsTest2()130 public void listCatalogsTest2() throws Exception { 131 Catalog responsesElement = Catalog.newBuilder().build(); 132 ListCatalogsResponse expectedResponse = 133 ListCatalogsResponse.newBuilder() 134 .setNextPageToken("") 135 .addAllCatalogs(Arrays.asList(responsesElement)) 136 .build(); 137 mockCatalogService.addResponse(expectedResponse); 138 139 String parent = "parent-995424086"; 140 141 ListCatalogsPagedResponse pagedListResponse = client.listCatalogs(parent); 142 143 List<Catalog> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 144 145 Assert.assertEquals(1, resources.size()); 146 Assert.assertEquals(expectedResponse.getCatalogsList().get(0), resources.get(0)); 147 148 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 149 Assert.assertEquals(1, actualRequests.size()); 150 ListCatalogsRequest actualRequest = ((ListCatalogsRequest) actualRequests.get(0)); 151 152 Assert.assertEquals(parent, actualRequest.getParent()); 153 Assert.assertTrue( 154 channelProvider.isHeaderSent( 155 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 156 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 157 } 158 159 @Test listCatalogsExceptionTest2()160 public void listCatalogsExceptionTest2() throws Exception { 161 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 162 mockCatalogService.addException(exception); 163 164 try { 165 String parent = "parent-995424086"; 166 client.listCatalogs(parent); 167 Assert.fail("No exception raised"); 168 } catch (InvalidArgumentException e) { 169 // Expected exception. 170 } 171 } 172 173 @Test updateCatalogTest()174 public void updateCatalogTest() throws Exception { 175 Catalog expectedResponse = 176 Catalog.newBuilder() 177 .setName(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 178 .setDisplayName("displayName1714148973") 179 .setProductLevelConfig(ProductLevelConfig.newBuilder().build()) 180 .build(); 181 mockCatalogService.addResponse(expectedResponse); 182 183 Catalog catalog = Catalog.newBuilder().build(); 184 FieldMask updateMask = FieldMask.newBuilder().build(); 185 186 Catalog actualResponse = client.updateCatalog(catalog, updateMask); 187 Assert.assertEquals(expectedResponse, actualResponse); 188 189 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 190 Assert.assertEquals(1, actualRequests.size()); 191 UpdateCatalogRequest actualRequest = ((UpdateCatalogRequest) actualRequests.get(0)); 192 193 Assert.assertEquals(catalog, actualRequest.getCatalog()); 194 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 195 Assert.assertTrue( 196 channelProvider.isHeaderSent( 197 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 198 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 199 } 200 201 @Test updateCatalogExceptionTest()202 public void updateCatalogExceptionTest() throws Exception { 203 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 204 mockCatalogService.addException(exception); 205 206 try { 207 Catalog catalog = Catalog.newBuilder().build(); 208 FieldMask updateMask = FieldMask.newBuilder().build(); 209 client.updateCatalog(catalog, updateMask); 210 Assert.fail("No exception raised"); 211 } catch (InvalidArgumentException e) { 212 // Expected exception. 213 } 214 } 215 216 @Test setDefaultBranchTest()217 public void setDefaultBranchTest() throws Exception { 218 Empty expectedResponse = Empty.newBuilder().build(); 219 mockCatalogService.addResponse(expectedResponse); 220 221 CatalogName catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 222 223 client.setDefaultBranch(catalog); 224 225 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 226 Assert.assertEquals(1, actualRequests.size()); 227 SetDefaultBranchRequest actualRequest = ((SetDefaultBranchRequest) actualRequests.get(0)); 228 229 Assert.assertEquals(catalog.toString(), actualRequest.getCatalog()); 230 Assert.assertTrue( 231 channelProvider.isHeaderSent( 232 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 233 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 234 } 235 236 @Test setDefaultBranchExceptionTest()237 public void setDefaultBranchExceptionTest() throws Exception { 238 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 239 mockCatalogService.addException(exception); 240 241 try { 242 CatalogName catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 243 client.setDefaultBranch(catalog); 244 Assert.fail("No exception raised"); 245 } catch (InvalidArgumentException e) { 246 // Expected exception. 247 } 248 } 249 250 @Test setDefaultBranchTest2()251 public void setDefaultBranchTest2() throws Exception { 252 Empty expectedResponse = Empty.newBuilder().build(); 253 mockCatalogService.addResponse(expectedResponse); 254 255 String catalog = "catalog555704345"; 256 257 client.setDefaultBranch(catalog); 258 259 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 260 Assert.assertEquals(1, actualRequests.size()); 261 SetDefaultBranchRequest actualRequest = ((SetDefaultBranchRequest) actualRequests.get(0)); 262 263 Assert.assertEquals(catalog, actualRequest.getCatalog()); 264 Assert.assertTrue( 265 channelProvider.isHeaderSent( 266 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 267 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 268 } 269 270 @Test setDefaultBranchExceptionTest2()271 public void setDefaultBranchExceptionTest2() throws Exception { 272 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 273 mockCatalogService.addException(exception); 274 275 try { 276 String catalog = "catalog555704345"; 277 client.setDefaultBranch(catalog); 278 Assert.fail("No exception raised"); 279 } catch (InvalidArgumentException e) { 280 // Expected exception. 281 } 282 } 283 284 @Test getDefaultBranchTest()285 public void getDefaultBranchTest() throws Exception { 286 GetDefaultBranchResponse expectedResponse = 287 GetDefaultBranchResponse.newBuilder() 288 .setBranch(BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString()) 289 .setSetTime(Timestamp.newBuilder().build()) 290 .setNote("note3387378") 291 .build(); 292 mockCatalogService.addResponse(expectedResponse); 293 294 CatalogName catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 295 296 GetDefaultBranchResponse actualResponse = client.getDefaultBranch(catalog); 297 Assert.assertEquals(expectedResponse, actualResponse); 298 299 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 300 Assert.assertEquals(1, actualRequests.size()); 301 GetDefaultBranchRequest actualRequest = ((GetDefaultBranchRequest) actualRequests.get(0)); 302 303 Assert.assertEquals(catalog.toString(), actualRequest.getCatalog()); 304 Assert.assertTrue( 305 channelProvider.isHeaderSent( 306 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 307 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 308 } 309 310 @Test getDefaultBranchExceptionTest()311 public void getDefaultBranchExceptionTest() throws Exception { 312 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 313 mockCatalogService.addException(exception); 314 315 try { 316 CatalogName catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 317 client.getDefaultBranch(catalog); 318 Assert.fail("No exception raised"); 319 } catch (InvalidArgumentException e) { 320 // Expected exception. 321 } 322 } 323 324 @Test getDefaultBranchTest2()325 public void getDefaultBranchTest2() throws Exception { 326 GetDefaultBranchResponse expectedResponse = 327 GetDefaultBranchResponse.newBuilder() 328 .setBranch(BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString()) 329 .setSetTime(Timestamp.newBuilder().build()) 330 .setNote("note3387378") 331 .build(); 332 mockCatalogService.addResponse(expectedResponse); 333 334 String catalog = "catalog555704345"; 335 336 GetDefaultBranchResponse actualResponse = client.getDefaultBranch(catalog); 337 Assert.assertEquals(expectedResponse, actualResponse); 338 339 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 340 Assert.assertEquals(1, actualRequests.size()); 341 GetDefaultBranchRequest actualRequest = ((GetDefaultBranchRequest) actualRequests.get(0)); 342 343 Assert.assertEquals(catalog, actualRequest.getCatalog()); 344 Assert.assertTrue( 345 channelProvider.isHeaderSent( 346 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 347 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 348 } 349 350 @Test getDefaultBranchExceptionTest2()351 public void getDefaultBranchExceptionTest2() throws Exception { 352 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 353 mockCatalogService.addException(exception); 354 355 try { 356 String catalog = "catalog555704345"; 357 client.getDefaultBranch(catalog); 358 Assert.fail("No exception raised"); 359 } catch (InvalidArgumentException e) { 360 // Expected exception. 361 } 362 } 363 364 @Test getCompletionConfigTest()365 public void getCompletionConfigTest() throws Exception { 366 CompletionConfig expectedResponse = 367 CompletionConfig.newBuilder() 368 .setName(CompletionConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 369 .setMatchingOrder("matchingOrder-1366761135") 370 .setMaxSuggestions(618824852) 371 .setMinPrefixLength(96853510) 372 .setAutoLearning(true) 373 .setSuggestionsInputConfig(CompletionDataInputConfig.newBuilder().build()) 374 .setLastSuggestionsImportOperation("lastSuggestionsImportOperation-245829751") 375 .setDenylistInputConfig(CompletionDataInputConfig.newBuilder().build()) 376 .setLastDenylistImportOperation("lastDenylistImportOperation1262341570") 377 .setAllowlistInputConfig(CompletionDataInputConfig.newBuilder().build()) 378 .setLastAllowlistImportOperation("lastAllowlistImportOperation1624716689") 379 .build(); 380 mockCatalogService.addResponse(expectedResponse); 381 382 CompletionConfigName name = CompletionConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 383 384 CompletionConfig actualResponse = client.getCompletionConfig(name); 385 Assert.assertEquals(expectedResponse, actualResponse); 386 387 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 388 Assert.assertEquals(1, actualRequests.size()); 389 GetCompletionConfigRequest actualRequest = ((GetCompletionConfigRequest) actualRequests.get(0)); 390 391 Assert.assertEquals(name.toString(), actualRequest.getName()); 392 Assert.assertTrue( 393 channelProvider.isHeaderSent( 394 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 395 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 396 } 397 398 @Test getCompletionConfigExceptionTest()399 public void getCompletionConfigExceptionTest() throws Exception { 400 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 401 mockCatalogService.addException(exception); 402 403 try { 404 CompletionConfigName name = CompletionConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 405 client.getCompletionConfig(name); 406 Assert.fail("No exception raised"); 407 } catch (InvalidArgumentException e) { 408 // Expected exception. 409 } 410 } 411 412 @Test getCompletionConfigTest2()413 public void getCompletionConfigTest2() throws Exception { 414 CompletionConfig expectedResponse = 415 CompletionConfig.newBuilder() 416 .setName(CompletionConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 417 .setMatchingOrder("matchingOrder-1366761135") 418 .setMaxSuggestions(618824852) 419 .setMinPrefixLength(96853510) 420 .setAutoLearning(true) 421 .setSuggestionsInputConfig(CompletionDataInputConfig.newBuilder().build()) 422 .setLastSuggestionsImportOperation("lastSuggestionsImportOperation-245829751") 423 .setDenylistInputConfig(CompletionDataInputConfig.newBuilder().build()) 424 .setLastDenylistImportOperation("lastDenylistImportOperation1262341570") 425 .setAllowlistInputConfig(CompletionDataInputConfig.newBuilder().build()) 426 .setLastAllowlistImportOperation("lastAllowlistImportOperation1624716689") 427 .build(); 428 mockCatalogService.addResponse(expectedResponse); 429 430 String name = "name3373707"; 431 432 CompletionConfig actualResponse = client.getCompletionConfig(name); 433 Assert.assertEquals(expectedResponse, actualResponse); 434 435 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 436 Assert.assertEquals(1, actualRequests.size()); 437 GetCompletionConfigRequest actualRequest = ((GetCompletionConfigRequest) actualRequests.get(0)); 438 439 Assert.assertEquals(name, actualRequest.getName()); 440 Assert.assertTrue( 441 channelProvider.isHeaderSent( 442 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 443 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 444 } 445 446 @Test getCompletionConfigExceptionTest2()447 public void getCompletionConfigExceptionTest2() throws Exception { 448 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 449 mockCatalogService.addException(exception); 450 451 try { 452 String name = "name3373707"; 453 client.getCompletionConfig(name); 454 Assert.fail("No exception raised"); 455 } catch (InvalidArgumentException e) { 456 // Expected exception. 457 } 458 } 459 460 @Test updateCompletionConfigTest()461 public void updateCompletionConfigTest() throws Exception { 462 CompletionConfig expectedResponse = 463 CompletionConfig.newBuilder() 464 .setName(CompletionConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 465 .setMatchingOrder("matchingOrder-1366761135") 466 .setMaxSuggestions(618824852) 467 .setMinPrefixLength(96853510) 468 .setAutoLearning(true) 469 .setSuggestionsInputConfig(CompletionDataInputConfig.newBuilder().build()) 470 .setLastSuggestionsImportOperation("lastSuggestionsImportOperation-245829751") 471 .setDenylistInputConfig(CompletionDataInputConfig.newBuilder().build()) 472 .setLastDenylistImportOperation("lastDenylistImportOperation1262341570") 473 .setAllowlistInputConfig(CompletionDataInputConfig.newBuilder().build()) 474 .setLastAllowlistImportOperation("lastAllowlistImportOperation1624716689") 475 .build(); 476 mockCatalogService.addResponse(expectedResponse); 477 478 CompletionConfig completionConfig = CompletionConfig.newBuilder().build(); 479 FieldMask updateMask = FieldMask.newBuilder().build(); 480 481 CompletionConfig actualResponse = client.updateCompletionConfig(completionConfig, updateMask); 482 Assert.assertEquals(expectedResponse, actualResponse); 483 484 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 485 Assert.assertEquals(1, actualRequests.size()); 486 UpdateCompletionConfigRequest actualRequest = 487 ((UpdateCompletionConfigRequest) actualRequests.get(0)); 488 489 Assert.assertEquals(completionConfig, actualRequest.getCompletionConfig()); 490 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 491 Assert.assertTrue( 492 channelProvider.isHeaderSent( 493 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 494 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 495 } 496 497 @Test updateCompletionConfigExceptionTest()498 public void updateCompletionConfigExceptionTest() throws Exception { 499 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 500 mockCatalogService.addException(exception); 501 502 try { 503 CompletionConfig completionConfig = CompletionConfig.newBuilder().build(); 504 FieldMask updateMask = FieldMask.newBuilder().build(); 505 client.updateCompletionConfig(completionConfig, updateMask); 506 Assert.fail("No exception raised"); 507 } catch (InvalidArgumentException e) { 508 // Expected exception. 509 } 510 } 511 512 @Test getAttributesConfigTest()513 public void getAttributesConfigTest() throws Exception { 514 AttributesConfig expectedResponse = 515 AttributesConfig.newBuilder() 516 .setName(AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 517 .putAllCatalogAttributes(new HashMap<String, CatalogAttribute>()) 518 .setAttributeConfigLevel(AttributeConfigLevel.forNumber(0)) 519 .build(); 520 mockCatalogService.addResponse(expectedResponse); 521 522 AttributesConfigName name = AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 523 524 AttributesConfig actualResponse = client.getAttributesConfig(name); 525 Assert.assertEquals(expectedResponse, actualResponse); 526 527 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 528 Assert.assertEquals(1, actualRequests.size()); 529 GetAttributesConfigRequest actualRequest = ((GetAttributesConfigRequest) actualRequests.get(0)); 530 531 Assert.assertEquals(name.toString(), actualRequest.getName()); 532 Assert.assertTrue( 533 channelProvider.isHeaderSent( 534 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 535 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 536 } 537 538 @Test getAttributesConfigExceptionTest()539 public void getAttributesConfigExceptionTest() throws Exception { 540 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 541 mockCatalogService.addException(exception); 542 543 try { 544 AttributesConfigName name = AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); 545 client.getAttributesConfig(name); 546 Assert.fail("No exception raised"); 547 } catch (InvalidArgumentException e) { 548 // Expected exception. 549 } 550 } 551 552 @Test getAttributesConfigTest2()553 public void getAttributesConfigTest2() throws Exception { 554 AttributesConfig expectedResponse = 555 AttributesConfig.newBuilder() 556 .setName(AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 557 .putAllCatalogAttributes(new HashMap<String, CatalogAttribute>()) 558 .setAttributeConfigLevel(AttributeConfigLevel.forNumber(0)) 559 .build(); 560 mockCatalogService.addResponse(expectedResponse); 561 562 String name = "name3373707"; 563 564 AttributesConfig actualResponse = client.getAttributesConfig(name); 565 Assert.assertEquals(expectedResponse, actualResponse); 566 567 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 568 Assert.assertEquals(1, actualRequests.size()); 569 GetAttributesConfigRequest actualRequest = ((GetAttributesConfigRequest) actualRequests.get(0)); 570 571 Assert.assertEquals(name, actualRequest.getName()); 572 Assert.assertTrue( 573 channelProvider.isHeaderSent( 574 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 575 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 576 } 577 578 @Test getAttributesConfigExceptionTest2()579 public void getAttributesConfigExceptionTest2() throws Exception { 580 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 581 mockCatalogService.addException(exception); 582 583 try { 584 String name = "name3373707"; 585 client.getAttributesConfig(name); 586 Assert.fail("No exception raised"); 587 } catch (InvalidArgumentException e) { 588 // Expected exception. 589 } 590 } 591 592 @Test updateAttributesConfigTest()593 public void updateAttributesConfigTest() throws Exception { 594 AttributesConfig expectedResponse = 595 AttributesConfig.newBuilder() 596 .setName(AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 597 .putAllCatalogAttributes(new HashMap<String, CatalogAttribute>()) 598 .setAttributeConfigLevel(AttributeConfigLevel.forNumber(0)) 599 .build(); 600 mockCatalogService.addResponse(expectedResponse); 601 602 AttributesConfig attributesConfig = AttributesConfig.newBuilder().build(); 603 FieldMask updateMask = FieldMask.newBuilder().build(); 604 605 AttributesConfig actualResponse = client.updateAttributesConfig(attributesConfig, updateMask); 606 Assert.assertEquals(expectedResponse, actualResponse); 607 608 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 609 Assert.assertEquals(1, actualRequests.size()); 610 UpdateAttributesConfigRequest actualRequest = 611 ((UpdateAttributesConfigRequest) actualRequests.get(0)); 612 613 Assert.assertEquals(attributesConfig, actualRequest.getAttributesConfig()); 614 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 615 Assert.assertTrue( 616 channelProvider.isHeaderSent( 617 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 618 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 619 } 620 621 @Test updateAttributesConfigExceptionTest()622 public void updateAttributesConfigExceptionTest() throws Exception { 623 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 624 mockCatalogService.addException(exception); 625 626 try { 627 AttributesConfig attributesConfig = AttributesConfig.newBuilder().build(); 628 FieldMask updateMask = FieldMask.newBuilder().build(); 629 client.updateAttributesConfig(attributesConfig, updateMask); 630 Assert.fail("No exception raised"); 631 } catch (InvalidArgumentException e) { 632 // Expected exception. 633 } 634 } 635 636 @Test addCatalogAttributeTest()637 public void addCatalogAttributeTest() throws Exception { 638 AttributesConfig expectedResponse = 639 AttributesConfig.newBuilder() 640 .setName(AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 641 .putAllCatalogAttributes(new HashMap<String, CatalogAttribute>()) 642 .setAttributeConfigLevel(AttributeConfigLevel.forNumber(0)) 643 .build(); 644 mockCatalogService.addResponse(expectedResponse); 645 646 AddCatalogAttributeRequest request = 647 AddCatalogAttributeRequest.newBuilder() 648 .setAttributesConfig( 649 AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 650 .setCatalogAttribute(CatalogAttribute.newBuilder().build()) 651 .build(); 652 653 AttributesConfig actualResponse = client.addCatalogAttribute(request); 654 Assert.assertEquals(expectedResponse, actualResponse); 655 656 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 657 Assert.assertEquals(1, actualRequests.size()); 658 AddCatalogAttributeRequest actualRequest = ((AddCatalogAttributeRequest) actualRequests.get(0)); 659 660 Assert.assertEquals(request.getAttributesConfig(), actualRequest.getAttributesConfig()); 661 Assert.assertEquals(request.getCatalogAttribute(), actualRequest.getCatalogAttribute()); 662 Assert.assertTrue( 663 channelProvider.isHeaderSent( 664 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 665 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 666 } 667 668 @Test addCatalogAttributeExceptionTest()669 public void addCatalogAttributeExceptionTest() throws Exception { 670 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 671 mockCatalogService.addException(exception); 672 673 try { 674 AddCatalogAttributeRequest request = 675 AddCatalogAttributeRequest.newBuilder() 676 .setAttributesConfig( 677 AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 678 .setCatalogAttribute(CatalogAttribute.newBuilder().build()) 679 .build(); 680 client.addCatalogAttribute(request); 681 Assert.fail("No exception raised"); 682 } catch (InvalidArgumentException e) { 683 // Expected exception. 684 } 685 } 686 687 @Test removeCatalogAttributeTest()688 public void removeCatalogAttributeTest() throws Exception { 689 AttributesConfig expectedResponse = 690 AttributesConfig.newBuilder() 691 .setName(AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 692 .putAllCatalogAttributes(new HashMap<String, CatalogAttribute>()) 693 .setAttributeConfigLevel(AttributeConfigLevel.forNumber(0)) 694 .build(); 695 mockCatalogService.addResponse(expectedResponse); 696 697 RemoveCatalogAttributeRequest request = 698 RemoveCatalogAttributeRequest.newBuilder() 699 .setAttributesConfig( 700 AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 701 .setKey("key106079") 702 .build(); 703 704 AttributesConfig actualResponse = client.removeCatalogAttribute(request); 705 Assert.assertEquals(expectedResponse, actualResponse); 706 707 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 708 Assert.assertEquals(1, actualRequests.size()); 709 RemoveCatalogAttributeRequest actualRequest = 710 ((RemoveCatalogAttributeRequest) actualRequests.get(0)); 711 712 Assert.assertEquals(request.getAttributesConfig(), actualRequest.getAttributesConfig()); 713 Assert.assertEquals(request.getKey(), actualRequest.getKey()); 714 Assert.assertTrue( 715 channelProvider.isHeaderSent( 716 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 717 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 718 } 719 720 @Test removeCatalogAttributeExceptionTest()721 public void removeCatalogAttributeExceptionTest() throws Exception { 722 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 723 mockCatalogService.addException(exception); 724 725 try { 726 RemoveCatalogAttributeRequest request = 727 RemoveCatalogAttributeRequest.newBuilder() 728 .setAttributesConfig( 729 AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 730 .setKey("key106079") 731 .build(); 732 client.removeCatalogAttribute(request); 733 Assert.fail("No exception raised"); 734 } catch (InvalidArgumentException e) { 735 // Expected exception. 736 } 737 } 738 739 @Test replaceCatalogAttributeTest()740 public void replaceCatalogAttributeTest() throws Exception { 741 AttributesConfig expectedResponse = 742 AttributesConfig.newBuilder() 743 .setName(AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 744 .putAllCatalogAttributes(new HashMap<String, CatalogAttribute>()) 745 .setAttributeConfigLevel(AttributeConfigLevel.forNumber(0)) 746 .build(); 747 mockCatalogService.addResponse(expectedResponse); 748 749 ReplaceCatalogAttributeRequest request = 750 ReplaceCatalogAttributeRequest.newBuilder() 751 .setAttributesConfig( 752 AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 753 .setCatalogAttribute(CatalogAttribute.newBuilder().build()) 754 .setUpdateMask(FieldMask.newBuilder().build()) 755 .build(); 756 757 AttributesConfig actualResponse = client.replaceCatalogAttribute(request); 758 Assert.assertEquals(expectedResponse, actualResponse); 759 760 List<AbstractMessage> actualRequests = mockCatalogService.getRequests(); 761 Assert.assertEquals(1, actualRequests.size()); 762 ReplaceCatalogAttributeRequest actualRequest = 763 ((ReplaceCatalogAttributeRequest) actualRequests.get(0)); 764 765 Assert.assertEquals(request.getAttributesConfig(), actualRequest.getAttributesConfig()); 766 Assert.assertEquals(request.getCatalogAttribute(), actualRequest.getCatalogAttribute()); 767 Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); 768 Assert.assertTrue( 769 channelProvider.isHeaderSent( 770 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 771 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 772 } 773 774 @Test replaceCatalogAttributeExceptionTest()775 public void replaceCatalogAttributeExceptionTest() throws Exception { 776 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 777 mockCatalogService.addException(exception); 778 779 try { 780 ReplaceCatalogAttributeRequest request = 781 ReplaceCatalogAttributeRequest.newBuilder() 782 .setAttributesConfig( 783 AttributesConfigName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) 784 .setCatalogAttribute(CatalogAttribute.newBuilder().build()) 785 .setUpdateMask(FieldMask.newBuilder().build()) 786 .build(); 787 client.replaceCatalogAttribute(request); 788 Assert.fail("No exception raised"); 789 } catch (InvalidArgumentException e) { 790 // Expected exception. 791 } 792 } 793 } 794