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.datafusion.v1beta1; 18 19 import static com.google.cloud.datafusion.v1beta1.DataFusionClient.ListAvailableVersionsPagedResponse; 20 import static com.google.cloud.datafusion.v1beta1.DataFusionClient.ListDnsPeeringsPagedResponse; 21 import static com.google.cloud.datafusion.v1beta1.DataFusionClient.ListInstancesPagedResponse; 22 import static com.google.cloud.datafusion.v1beta1.DataFusionClient.ListNamespacesPagedResponse; 23 24 import com.google.api.gax.core.NoCredentialsProvider; 25 import com.google.api.gax.httpjson.GaxHttpJsonProperties; 26 import com.google.api.gax.httpjson.testing.MockHttpService; 27 import com.google.api.gax.rpc.ApiClientHeaderProvider; 28 import com.google.api.gax.rpc.ApiException; 29 import com.google.api.gax.rpc.ApiExceptionFactory; 30 import com.google.api.gax.rpc.InvalidArgumentException; 31 import com.google.api.gax.rpc.StatusCode; 32 import com.google.api.gax.rpc.testing.FakeStatusCode; 33 import com.google.cloud.datafusion.v1beta1.stub.HttpJsonDataFusionStub; 34 import com.google.common.collect.Lists; 35 import com.google.longrunning.Operation; 36 import com.google.protobuf.Any; 37 import com.google.protobuf.Empty; 38 import com.google.protobuf.FieldMask; 39 import com.google.protobuf.Timestamp; 40 import java.io.IOException; 41 import java.util.ArrayList; 42 import java.util.Arrays; 43 import java.util.HashMap; 44 import java.util.List; 45 import java.util.concurrent.ExecutionException; 46 import javax.annotation.Generated; 47 import org.junit.After; 48 import org.junit.AfterClass; 49 import org.junit.Assert; 50 import org.junit.Before; 51 import org.junit.BeforeClass; 52 import org.junit.Test; 53 54 @Generated("by gapic-generator-java") 55 public class DataFusionClientHttpJsonTest { 56 private static MockHttpService mockService; 57 private static DataFusionClient client; 58 59 @BeforeClass startStaticServer()60 public static void startStaticServer() throws IOException { 61 mockService = 62 new MockHttpService( 63 HttpJsonDataFusionStub.getMethodDescriptors(), DataFusionSettings.getDefaultEndpoint()); 64 DataFusionSettings settings = 65 DataFusionSettings.newHttpJsonBuilder() 66 .setTransportChannelProvider( 67 DataFusionSettings.defaultHttpJsonTransportProviderBuilder() 68 .setHttpTransport(mockService) 69 .build()) 70 .setCredentialsProvider(NoCredentialsProvider.create()) 71 .build(); 72 client = DataFusionClient.create(settings); 73 } 74 75 @AfterClass stopServer()76 public static void stopServer() { 77 client.close(); 78 } 79 80 @Before setUp()81 public void setUp() {} 82 83 @After tearDown()84 public void tearDown() throws Exception { 85 mockService.reset(); 86 } 87 88 @Test listAvailableVersionsTest()89 public void listAvailableVersionsTest() throws Exception { 90 Version responsesElement = Version.newBuilder().build(); 91 ListAvailableVersionsResponse expectedResponse = 92 ListAvailableVersionsResponse.newBuilder() 93 .setNextPageToken("") 94 .addAllAvailableVersions(Arrays.asList(responsesElement)) 95 .build(); 96 mockService.addResponse(expectedResponse); 97 98 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 99 100 ListAvailableVersionsPagedResponse pagedListResponse = client.listAvailableVersions(parent); 101 102 List<Version> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 103 104 Assert.assertEquals(1, resources.size()); 105 Assert.assertEquals(expectedResponse.getAvailableVersionsList().get(0), resources.get(0)); 106 107 List<String> actualRequests = mockService.getRequestPaths(); 108 Assert.assertEquals(1, actualRequests.size()); 109 110 String apiClientHeaderKey = 111 mockService 112 .getRequestHeaders() 113 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 114 .iterator() 115 .next(); 116 Assert.assertTrue( 117 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 118 .matcher(apiClientHeaderKey) 119 .matches()); 120 } 121 122 @Test listAvailableVersionsExceptionTest()123 public void listAvailableVersionsExceptionTest() throws Exception { 124 ApiException exception = 125 ApiExceptionFactory.createException( 126 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 127 mockService.addException(exception); 128 129 try { 130 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 131 client.listAvailableVersions(parent); 132 Assert.fail("No exception raised"); 133 } catch (InvalidArgumentException e) { 134 // Expected exception. 135 } 136 } 137 138 @Test listAvailableVersionsTest2()139 public void listAvailableVersionsTest2() throws Exception { 140 Version responsesElement = Version.newBuilder().build(); 141 ListAvailableVersionsResponse expectedResponse = 142 ListAvailableVersionsResponse.newBuilder() 143 .setNextPageToken("") 144 .addAllAvailableVersions(Arrays.asList(responsesElement)) 145 .build(); 146 mockService.addResponse(expectedResponse); 147 148 String parent = "projects/project-5833/locations/location-5833"; 149 150 ListAvailableVersionsPagedResponse pagedListResponse = client.listAvailableVersions(parent); 151 152 List<Version> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 153 154 Assert.assertEquals(1, resources.size()); 155 Assert.assertEquals(expectedResponse.getAvailableVersionsList().get(0), resources.get(0)); 156 157 List<String> actualRequests = mockService.getRequestPaths(); 158 Assert.assertEquals(1, actualRequests.size()); 159 160 String apiClientHeaderKey = 161 mockService 162 .getRequestHeaders() 163 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 164 .iterator() 165 .next(); 166 Assert.assertTrue( 167 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 168 .matcher(apiClientHeaderKey) 169 .matches()); 170 } 171 172 @Test listAvailableVersionsExceptionTest2()173 public void listAvailableVersionsExceptionTest2() throws Exception { 174 ApiException exception = 175 ApiExceptionFactory.createException( 176 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 177 mockService.addException(exception); 178 179 try { 180 String parent = "projects/project-5833/locations/location-5833"; 181 client.listAvailableVersions(parent); 182 Assert.fail("No exception raised"); 183 } catch (InvalidArgumentException e) { 184 // Expected exception. 185 } 186 } 187 188 @Test listInstancesTest()189 public void listInstancesTest() throws Exception { 190 Instance responsesElement = Instance.newBuilder().build(); 191 ListInstancesResponse expectedResponse = 192 ListInstancesResponse.newBuilder() 193 .setNextPageToken("") 194 .addAllInstances(Arrays.asList(responsesElement)) 195 .build(); 196 mockService.addResponse(expectedResponse); 197 198 ListInstancesRequest request = 199 ListInstancesRequest.newBuilder() 200 .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 201 .setPageSize(883849137) 202 .setPageToken("pageToken873572522") 203 .setFilter("filter-1274492040") 204 .setOrderBy("orderBy-1207110587") 205 .build(); 206 207 ListInstancesPagedResponse pagedListResponse = client.listInstances(request); 208 209 List<Instance> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 210 211 Assert.assertEquals(1, resources.size()); 212 Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0)); 213 214 List<String> actualRequests = mockService.getRequestPaths(); 215 Assert.assertEquals(1, actualRequests.size()); 216 217 String apiClientHeaderKey = 218 mockService 219 .getRequestHeaders() 220 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 221 .iterator() 222 .next(); 223 Assert.assertTrue( 224 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 225 .matcher(apiClientHeaderKey) 226 .matches()); 227 } 228 229 @Test listInstancesExceptionTest()230 public void listInstancesExceptionTest() throws Exception { 231 ApiException exception = 232 ApiExceptionFactory.createException( 233 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 234 mockService.addException(exception); 235 236 try { 237 ListInstancesRequest request = 238 ListInstancesRequest.newBuilder() 239 .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) 240 .setPageSize(883849137) 241 .setPageToken("pageToken873572522") 242 .setFilter("filter-1274492040") 243 .setOrderBy("orderBy-1207110587") 244 .build(); 245 client.listInstances(request); 246 Assert.fail("No exception raised"); 247 } catch (InvalidArgumentException e) { 248 // Expected exception. 249 } 250 } 251 252 @Test getInstanceTest()253 public void getInstanceTest() throws Exception { 254 Instance expectedResponse = 255 Instance.newBuilder() 256 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 257 .setDescription("description-1724546052") 258 .setEnableStackdriverLogging(true) 259 .setEnableStackdriverMonitoring(true) 260 .setPrivateInstance(true) 261 .setNetworkConfig(NetworkConfig.newBuilder().build()) 262 .putAllLabels(new HashMap<String, String>()) 263 .putAllOptions(new HashMap<String, String>()) 264 .setCreateTime(Timestamp.newBuilder().build()) 265 .setUpdateTime(Timestamp.newBuilder().build()) 266 .setStateMessage("stateMessage1128185398") 267 .setServiceEndpoint("serviceEndpoint-1323187350") 268 .setZone("zone3744684") 269 .setVersion("version351608024") 270 .setServiceAccount("serviceAccount1079137720") 271 .setDisplayName("displayName1714148973") 272 .addAllAvailableVersion(new ArrayList<Version>()) 273 .setApiEndpoint("apiEndpoint-2038677041") 274 .setGcsBucket("gcsBucket239654881") 275 .addAllAccelerators(new ArrayList<Accelerator>()) 276 .setP4ServiceAccount("p4ServiceAccount-184825700") 277 .setTenantProjectId("tenantProjectId674318474") 278 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 279 .setEnableRbac(true) 280 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 281 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 282 .build(); 283 mockService.addResponse(expectedResponse); 284 285 GetInstanceRequest request = 286 GetInstanceRequest.newBuilder() 287 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 288 .build(); 289 290 Instance actualResponse = client.getInstance(request); 291 Assert.assertEquals(expectedResponse, actualResponse); 292 293 List<String> actualRequests = mockService.getRequestPaths(); 294 Assert.assertEquals(1, actualRequests.size()); 295 296 String apiClientHeaderKey = 297 mockService 298 .getRequestHeaders() 299 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 300 .iterator() 301 .next(); 302 Assert.assertTrue( 303 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 304 .matcher(apiClientHeaderKey) 305 .matches()); 306 } 307 308 @Test getInstanceExceptionTest()309 public void getInstanceExceptionTest() throws Exception { 310 ApiException exception = 311 ApiExceptionFactory.createException( 312 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 313 mockService.addException(exception); 314 315 try { 316 GetInstanceRequest request = 317 GetInstanceRequest.newBuilder() 318 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 319 .build(); 320 client.getInstance(request); 321 Assert.fail("No exception raised"); 322 } catch (InvalidArgumentException e) { 323 // Expected exception. 324 } 325 } 326 327 @Test createInstanceTest()328 public void createInstanceTest() throws Exception { 329 Instance expectedResponse = 330 Instance.newBuilder() 331 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 332 .setDescription("description-1724546052") 333 .setEnableStackdriverLogging(true) 334 .setEnableStackdriverMonitoring(true) 335 .setPrivateInstance(true) 336 .setNetworkConfig(NetworkConfig.newBuilder().build()) 337 .putAllLabels(new HashMap<String, String>()) 338 .putAllOptions(new HashMap<String, String>()) 339 .setCreateTime(Timestamp.newBuilder().build()) 340 .setUpdateTime(Timestamp.newBuilder().build()) 341 .setStateMessage("stateMessage1128185398") 342 .setServiceEndpoint("serviceEndpoint-1323187350") 343 .setZone("zone3744684") 344 .setVersion("version351608024") 345 .setServiceAccount("serviceAccount1079137720") 346 .setDisplayName("displayName1714148973") 347 .addAllAvailableVersion(new ArrayList<Version>()) 348 .setApiEndpoint("apiEndpoint-2038677041") 349 .setGcsBucket("gcsBucket239654881") 350 .addAllAccelerators(new ArrayList<Accelerator>()) 351 .setP4ServiceAccount("p4ServiceAccount-184825700") 352 .setTenantProjectId("tenantProjectId674318474") 353 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 354 .setEnableRbac(true) 355 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 356 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 357 .build(); 358 Operation resultOperation = 359 Operation.newBuilder() 360 .setName("createInstanceTest") 361 .setDone(true) 362 .setResponse(Any.pack(expectedResponse)) 363 .build(); 364 mockService.addResponse(resultOperation); 365 366 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 367 Instance instance = Instance.newBuilder().build(); 368 String instanceId = "instanceId902024336"; 369 370 Instance actualResponse = client.createInstanceAsync(parent, instance, instanceId).get(); 371 Assert.assertEquals(expectedResponse, actualResponse); 372 373 List<String> actualRequests = mockService.getRequestPaths(); 374 Assert.assertEquals(1, actualRequests.size()); 375 376 String apiClientHeaderKey = 377 mockService 378 .getRequestHeaders() 379 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 380 .iterator() 381 .next(); 382 Assert.assertTrue( 383 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 384 .matcher(apiClientHeaderKey) 385 .matches()); 386 } 387 388 @Test createInstanceExceptionTest()389 public void createInstanceExceptionTest() throws Exception { 390 ApiException exception = 391 ApiExceptionFactory.createException( 392 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 393 mockService.addException(exception); 394 395 try { 396 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 397 Instance instance = Instance.newBuilder().build(); 398 String instanceId = "instanceId902024336"; 399 client.createInstanceAsync(parent, instance, instanceId).get(); 400 Assert.fail("No exception raised"); 401 } catch (ExecutionException e) { 402 } 403 } 404 405 @Test createInstanceTest2()406 public void createInstanceTest2() throws Exception { 407 Instance expectedResponse = 408 Instance.newBuilder() 409 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 410 .setDescription("description-1724546052") 411 .setEnableStackdriverLogging(true) 412 .setEnableStackdriverMonitoring(true) 413 .setPrivateInstance(true) 414 .setNetworkConfig(NetworkConfig.newBuilder().build()) 415 .putAllLabels(new HashMap<String, String>()) 416 .putAllOptions(new HashMap<String, String>()) 417 .setCreateTime(Timestamp.newBuilder().build()) 418 .setUpdateTime(Timestamp.newBuilder().build()) 419 .setStateMessage("stateMessage1128185398") 420 .setServiceEndpoint("serviceEndpoint-1323187350") 421 .setZone("zone3744684") 422 .setVersion("version351608024") 423 .setServiceAccount("serviceAccount1079137720") 424 .setDisplayName("displayName1714148973") 425 .addAllAvailableVersion(new ArrayList<Version>()) 426 .setApiEndpoint("apiEndpoint-2038677041") 427 .setGcsBucket("gcsBucket239654881") 428 .addAllAccelerators(new ArrayList<Accelerator>()) 429 .setP4ServiceAccount("p4ServiceAccount-184825700") 430 .setTenantProjectId("tenantProjectId674318474") 431 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 432 .setEnableRbac(true) 433 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 434 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 435 .build(); 436 Operation resultOperation = 437 Operation.newBuilder() 438 .setName("createInstanceTest") 439 .setDone(true) 440 .setResponse(Any.pack(expectedResponse)) 441 .build(); 442 mockService.addResponse(resultOperation); 443 444 String parent = "projects/project-5833/locations/location-5833"; 445 Instance instance = Instance.newBuilder().build(); 446 String instanceId = "instanceId902024336"; 447 448 Instance actualResponse = client.createInstanceAsync(parent, instance, instanceId).get(); 449 Assert.assertEquals(expectedResponse, actualResponse); 450 451 List<String> actualRequests = mockService.getRequestPaths(); 452 Assert.assertEquals(1, actualRequests.size()); 453 454 String apiClientHeaderKey = 455 mockService 456 .getRequestHeaders() 457 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 458 .iterator() 459 .next(); 460 Assert.assertTrue( 461 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 462 .matcher(apiClientHeaderKey) 463 .matches()); 464 } 465 466 @Test createInstanceExceptionTest2()467 public void createInstanceExceptionTest2() throws Exception { 468 ApiException exception = 469 ApiExceptionFactory.createException( 470 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 471 mockService.addException(exception); 472 473 try { 474 String parent = "projects/project-5833/locations/location-5833"; 475 Instance instance = Instance.newBuilder().build(); 476 String instanceId = "instanceId902024336"; 477 client.createInstanceAsync(parent, instance, instanceId).get(); 478 Assert.fail("No exception raised"); 479 } catch (ExecutionException e) { 480 } 481 } 482 483 @Test deleteInstanceTest()484 public void deleteInstanceTest() throws Exception { 485 Empty expectedResponse = Empty.newBuilder().build(); 486 Operation resultOperation = 487 Operation.newBuilder() 488 .setName("deleteInstanceTest") 489 .setDone(true) 490 .setResponse(Any.pack(expectedResponse)) 491 .build(); 492 mockService.addResponse(resultOperation); 493 494 InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 495 496 client.deleteInstanceAsync(name).get(); 497 498 List<String> actualRequests = mockService.getRequestPaths(); 499 Assert.assertEquals(1, actualRequests.size()); 500 501 String apiClientHeaderKey = 502 mockService 503 .getRequestHeaders() 504 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 505 .iterator() 506 .next(); 507 Assert.assertTrue( 508 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 509 .matcher(apiClientHeaderKey) 510 .matches()); 511 } 512 513 @Test deleteInstanceExceptionTest()514 public void deleteInstanceExceptionTest() throws Exception { 515 ApiException exception = 516 ApiExceptionFactory.createException( 517 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 518 mockService.addException(exception); 519 520 try { 521 InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 522 client.deleteInstanceAsync(name).get(); 523 Assert.fail("No exception raised"); 524 } catch (ExecutionException e) { 525 } 526 } 527 528 @Test deleteInstanceTest2()529 public void deleteInstanceTest2() throws Exception { 530 Empty expectedResponse = Empty.newBuilder().build(); 531 Operation resultOperation = 532 Operation.newBuilder() 533 .setName("deleteInstanceTest") 534 .setDone(true) 535 .setResponse(Any.pack(expectedResponse)) 536 .build(); 537 mockService.addResponse(resultOperation); 538 539 String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; 540 541 client.deleteInstanceAsync(name).get(); 542 543 List<String> actualRequests = mockService.getRequestPaths(); 544 Assert.assertEquals(1, actualRequests.size()); 545 546 String apiClientHeaderKey = 547 mockService 548 .getRequestHeaders() 549 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 550 .iterator() 551 .next(); 552 Assert.assertTrue( 553 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 554 .matcher(apiClientHeaderKey) 555 .matches()); 556 } 557 558 @Test deleteInstanceExceptionTest2()559 public void deleteInstanceExceptionTest2() throws Exception { 560 ApiException exception = 561 ApiExceptionFactory.createException( 562 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 563 mockService.addException(exception); 564 565 try { 566 String name = "projects/project-9412/locations/location-9412/instances/instance-9412"; 567 client.deleteInstanceAsync(name).get(); 568 Assert.fail("No exception raised"); 569 } catch (ExecutionException e) { 570 } 571 } 572 573 @Test updateInstanceTest()574 public void updateInstanceTest() throws Exception { 575 Instance expectedResponse = 576 Instance.newBuilder() 577 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 578 .setDescription("description-1724546052") 579 .setEnableStackdriverLogging(true) 580 .setEnableStackdriverMonitoring(true) 581 .setPrivateInstance(true) 582 .setNetworkConfig(NetworkConfig.newBuilder().build()) 583 .putAllLabels(new HashMap<String, String>()) 584 .putAllOptions(new HashMap<String, String>()) 585 .setCreateTime(Timestamp.newBuilder().build()) 586 .setUpdateTime(Timestamp.newBuilder().build()) 587 .setStateMessage("stateMessage1128185398") 588 .setServiceEndpoint("serviceEndpoint-1323187350") 589 .setZone("zone3744684") 590 .setVersion("version351608024") 591 .setServiceAccount("serviceAccount1079137720") 592 .setDisplayName("displayName1714148973") 593 .addAllAvailableVersion(new ArrayList<Version>()) 594 .setApiEndpoint("apiEndpoint-2038677041") 595 .setGcsBucket("gcsBucket239654881") 596 .addAllAccelerators(new ArrayList<Accelerator>()) 597 .setP4ServiceAccount("p4ServiceAccount-184825700") 598 .setTenantProjectId("tenantProjectId674318474") 599 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 600 .setEnableRbac(true) 601 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 602 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 603 .build(); 604 Operation resultOperation = 605 Operation.newBuilder() 606 .setName("updateInstanceTest") 607 .setDone(true) 608 .setResponse(Any.pack(expectedResponse)) 609 .build(); 610 mockService.addResponse(resultOperation); 611 612 Instance instance = 613 Instance.newBuilder() 614 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 615 .setDescription("description-1724546052") 616 .setEnableStackdriverLogging(true) 617 .setEnableStackdriverMonitoring(true) 618 .setPrivateInstance(true) 619 .setNetworkConfig(NetworkConfig.newBuilder().build()) 620 .putAllLabels(new HashMap<String, String>()) 621 .putAllOptions(new HashMap<String, String>()) 622 .setCreateTime(Timestamp.newBuilder().build()) 623 .setUpdateTime(Timestamp.newBuilder().build()) 624 .setStateMessage("stateMessage1128185398") 625 .setServiceEndpoint("serviceEndpoint-1323187350") 626 .setZone("zone3744684") 627 .setVersion("version351608024") 628 .setServiceAccount("serviceAccount1079137720") 629 .setDisplayName("displayName1714148973") 630 .addAllAvailableVersion(new ArrayList<Version>()) 631 .setApiEndpoint("apiEndpoint-2038677041") 632 .setGcsBucket("gcsBucket239654881") 633 .addAllAccelerators(new ArrayList<Accelerator>()) 634 .setP4ServiceAccount("p4ServiceAccount-184825700") 635 .setTenantProjectId("tenantProjectId674318474") 636 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 637 .setEnableRbac(true) 638 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 639 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 640 .build(); 641 FieldMask updateMask = FieldMask.newBuilder().build(); 642 643 Instance actualResponse = client.updateInstanceAsync(instance, updateMask).get(); 644 Assert.assertEquals(expectedResponse, actualResponse); 645 646 List<String> actualRequests = mockService.getRequestPaths(); 647 Assert.assertEquals(1, actualRequests.size()); 648 649 String apiClientHeaderKey = 650 mockService 651 .getRequestHeaders() 652 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 653 .iterator() 654 .next(); 655 Assert.assertTrue( 656 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 657 .matcher(apiClientHeaderKey) 658 .matches()); 659 } 660 661 @Test updateInstanceExceptionTest()662 public void updateInstanceExceptionTest() throws Exception { 663 ApiException exception = 664 ApiExceptionFactory.createException( 665 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 666 mockService.addException(exception); 667 668 try { 669 Instance instance = 670 Instance.newBuilder() 671 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 672 .setDescription("description-1724546052") 673 .setEnableStackdriverLogging(true) 674 .setEnableStackdriverMonitoring(true) 675 .setPrivateInstance(true) 676 .setNetworkConfig(NetworkConfig.newBuilder().build()) 677 .putAllLabels(new HashMap<String, String>()) 678 .putAllOptions(new HashMap<String, String>()) 679 .setCreateTime(Timestamp.newBuilder().build()) 680 .setUpdateTime(Timestamp.newBuilder().build()) 681 .setStateMessage("stateMessage1128185398") 682 .setServiceEndpoint("serviceEndpoint-1323187350") 683 .setZone("zone3744684") 684 .setVersion("version351608024") 685 .setServiceAccount("serviceAccount1079137720") 686 .setDisplayName("displayName1714148973") 687 .addAllAvailableVersion(new ArrayList<Version>()) 688 .setApiEndpoint("apiEndpoint-2038677041") 689 .setGcsBucket("gcsBucket239654881") 690 .addAllAccelerators(new ArrayList<Accelerator>()) 691 .setP4ServiceAccount("p4ServiceAccount-184825700") 692 .setTenantProjectId("tenantProjectId674318474") 693 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 694 .setEnableRbac(true) 695 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 696 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 697 .build(); 698 FieldMask updateMask = FieldMask.newBuilder().build(); 699 client.updateInstanceAsync(instance, updateMask).get(); 700 Assert.fail("No exception raised"); 701 } catch (ExecutionException e) { 702 } 703 } 704 705 @Test restartInstanceTest()706 public void restartInstanceTest() throws Exception { 707 Instance expectedResponse = 708 Instance.newBuilder() 709 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 710 .setDescription("description-1724546052") 711 .setEnableStackdriverLogging(true) 712 .setEnableStackdriverMonitoring(true) 713 .setPrivateInstance(true) 714 .setNetworkConfig(NetworkConfig.newBuilder().build()) 715 .putAllLabels(new HashMap<String, String>()) 716 .putAllOptions(new HashMap<String, String>()) 717 .setCreateTime(Timestamp.newBuilder().build()) 718 .setUpdateTime(Timestamp.newBuilder().build()) 719 .setStateMessage("stateMessage1128185398") 720 .setServiceEndpoint("serviceEndpoint-1323187350") 721 .setZone("zone3744684") 722 .setVersion("version351608024") 723 .setServiceAccount("serviceAccount1079137720") 724 .setDisplayName("displayName1714148973") 725 .addAllAvailableVersion(new ArrayList<Version>()) 726 .setApiEndpoint("apiEndpoint-2038677041") 727 .setGcsBucket("gcsBucket239654881") 728 .addAllAccelerators(new ArrayList<Accelerator>()) 729 .setP4ServiceAccount("p4ServiceAccount-184825700") 730 .setTenantProjectId("tenantProjectId674318474") 731 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 732 .setEnableRbac(true) 733 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 734 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 735 .build(); 736 Operation resultOperation = 737 Operation.newBuilder() 738 .setName("restartInstanceTest") 739 .setDone(true) 740 .setResponse(Any.pack(expectedResponse)) 741 .build(); 742 mockService.addResponse(resultOperation); 743 744 RestartInstanceRequest request = 745 RestartInstanceRequest.newBuilder() 746 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 747 .build(); 748 749 Instance actualResponse = client.restartInstanceAsync(request).get(); 750 Assert.assertEquals(expectedResponse, actualResponse); 751 752 List<String> actualRequests = mockService.getRequestPaths(); 753 Assert.assertEquals(1, actualRequests.size()); 754 755 String apiClientHeaderKey = 756 mockService 757 .getRequestHeaders() 758 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 759 .iterator() 760 .next(); 761 Assert.assertTrue( 762 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 763 .matcher(apiClientHeaderKey) 764 .matches()); 765 } 766 767 @Test restartInstanceExceptionTest()768 public void restartInstanceExceptionTest() throws Exception { 769 ApiException exception = 770 ApiExceptionFactory.createException( 771 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 772 mockService.addException(exception); 773 774 try { 775 RestartInstanceRequest request = 776 RestartInstanceRequest.newBuilder() 777 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 778 .build(); 779 client.restartInstanceAsync(request).get(); 780 Assert.fail("No exception raised"); 781 } catch (ExecutionException e) { 782 } 783 } 784 785 @Test upgradeInstanceTest()786 public void upgradeInstanceTest() throws Exception { 787 Instance expectedResponse = 788 Instance.newBuilder() 789 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 790 .setDescription("description-1724546052") 791 .setEnableStackdriverLogging(true) 792 .setEnableStackdriverMonitoring(true) 793 .setPrivateInstance(true) 794 .setNetworkConfig(NetworkConfig.newBuilder().build()) 795 .putAllLabels(new HashMap<String, String>()) 796 .putAllOptions(new HashMap<String, String>()) 797 .setCreateTime(Timestamp.newBuilder().build()) 798 .setUpdateTime(Timestamp.newBuilder().build()) 799 .setStateMessage("stateMessage1128185398") 800 .setServiceEndpoint("serviceEndpoint-1323187350") 801 .setZone("zone3744684") 802 .setVersion("version351608024") 803 .setServiceAccount("serviceAccount1079137720") 804 .setDisplayName("displayName1714148973") 805 .addAllAvailableVersion(new ArrayList<Version>()) 806 .setApiEndpoint("apiEndpoint-2038677041") 807 .setGcsBucket("gcsBucket239654881") 808 .addAllAccelerators(new ArrayList<Accelerator>()) 809 .setP4ServiceAccount("p4ServiceAccount-184825700") 810 .setTenantProjectId("tenantProjectId674318474") 811 .setDataprocServiceAccount("dataprocServiceAccount-1287630888") 812 .setEnableRbac(true) 813 .setCryptoKeyConfig(CryptoKeyConfig.newBuilder().build()) 814 .addAllDisabledReason(new ArrayList<Instance.DisabledReason>()) 815 .build(); 816 Operation resultOperation = 817 Operation.newBuilder() 818 .setName("upgradeInstanceTest") 819 .setDone(true) 820 .setResponse(Any.pack(expectedResponse)) 821 .build(); 822 mockService.addResponse(resultOperation); 823 824 UpgradeInstanceRequest request = 825 UpgradeInstanceRequest.newBuilder() 826 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 827 .build(); 828 829 Instance actualResponse = client.upgradeInstanceAsync(request).get(); 830 Assert.assertEquals(expectedResponse, actualResponse); 831 832 List<String> actualRequests = mockService.getRequestPaths(); 833 Assert.assertEquals(1, actualRequests.size()); 834 835 String apiClientHeaderKey = 836 mockService 837 .getRequestHeaders() 838 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 839 .iterator() 840 .next(); 841 Assert.assertTrue( 842 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 843 .matcher(apiClientHeaderKey) 844 .matches()); 845 } 846 847 @Test upgradeInstanceExceptionTest()848 public void upgradeInstanceExceptionTest() throws Exception { 849 ApiException exception = 850 ApiExceptionFactory.createException( 851 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 852 mockService.addException(exception); 853 854 try { 855 UpgradeInstanceRequest request = 856 UpgradeInstanceRequest.newBuilder() 857 .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) 858 .build(); 859 client.upgradeInstanceAsync(request).get(); 860 Assert.fail("No exception raised"); 861 } catch (ExecutionException e) { 862 } 863 } 864 865 @Test removeIamPolicyTest()866 public void removeIamPolicyTest() throws Exception { 867 RemoveIamPolicyResponse expectedResponse = RemoveIamPolicyResponse.newBuilder().build(); 868 mockService.addResponse(expectedResponse); 869 870 RemoveIamPolicyRequest request = 871 RemoveIamPolicyRequest.newBuilder() 872 .setResource("projects/project-6942/locations/location-6942/location-6942") 873 .build(); 874 875 RemoveIamPolicyResponse actualResponse = client.removeIamPolicy(request); 876 Assert.assertEquals(expectedResponse, actualResponse); 877 878 List<String> actualRequests = mockService.getRequestPaths(); 879 Assert.assertEquals(1, actualRequests.size()); 880 881 String apiClientHeaderKey = 882 mockService 883 .getRequestHeaders() 884 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 885 .iterator() 886 .next(); 887 Assert.assertTrue( 888 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 889 .matcher(apiClientHeaderKey) 890 .matches()); 891 } 892 893 @Test removeIamPolicyExceptionTest()894 public void removeIamPolicyExceptionTest() throws Exception { 895 ApiException exception = 896 ApiExceptionFactory.createException( 897 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 898 mockService.addException(exception); 899 900 try { 901 RemoveIamPolicyRequest request = 902 RemoveIamPolicyRequest.newBuilder() 903 .setResource("projects/project-6942/locations/location-6942/location-6942") 904 .build(); 905 client.removeIamPolicy(request); 906 Assert.fail("No exception raised"); 907 } catch (InvalidArgumentException e) { 908 // Expected exception. 909 } 910 } 911 912 @Test listNamespacesTest()913 public void listNamespacesTest() throws Exception { 914 Namespace responsesElement = Namespace.newBuilder().build(); 915 ListNamespacesResponse expectedResponse = 916 ListNamespacesResponse.newBuilder() 917 .setNextPageToken("") 918 .addAllNamespaces(Arrays.asList(responsesElement)) 919 .build(); 920 mockService.addResponse(expectedResponse); 921 922 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 923 924 ListNamespacesPagedResponse pagedListResponse = client.listNamespaces(parent); 925 926 List<Namespace> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 927 928 Assert.assertEquals(1, resources.size()); 929 Assert.assertEquals(expectedResponse.getNamespacesList().get(0), resources.get(0)); 930 931 List<String> actualRequests = mockService.getRequestPaths(); 932 Assert.assertEquals(1, actualRequests.size()); 933 934 String apiClientHeaderKey = 935 mockService 936 .getRequestHeaders() 937 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 938 .iterator() 939 .next(); 940 Assert.assertTrue( 941 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 942 .matcher(apiClientHeaderKey) 943 .matches()); 944 } 945 946 @Test listNamespacesExceptionTest()947 public void listNamespacesExceptionTest() throws Exception { 948 ApiException exception = 949 ApiExceptionFactory.createException( 950 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 951 mockService.addException(exception); 952 953 try { 954 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 955 client.listNamespaces(parent); 956 Assert.fail("No exception raised"); 957 } catch (InvalidArgumentException e) { 958 // Expected exception. 959 } 960 } 961 962 @Test listNamespacesTest2()963 public void listNamespacesTest2() throws Exception { 964 Namespace responsesElement = Namespace.newBuilder().build(); 965 ListNamespacesResponse expectedResponse = 966 ListNamespacesResponse.newBuilder() 967 .setNextPageToken("") 968 .addAllNamespaces(Arrays.asList(responsesElement)) 969 .build(); 970 mockService.addResponse(expectedResponse); 971 972 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 973 974 ListNamespacesPagedResponse pagedListResponse = client.listNamespaces(parent); 975 976 List<Namespace> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 977 978 Assert.assertEquals(1, resources.size()); 979 Assert.assertEquals(expectedResponse.getNamespacesList().get(0), resources.get(0)); 980 981 List<String> actualRequests = mockService.getRequestPaths(); 982 Assert.assertEquals(1, actualRequests.size()); 983 984 String apiClientHeaderKey = 985 mockService 986 .getRequestHeaders() 987 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 988 .iterator() 989 .next(); 990 Assert.assertTrue( 991 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 992 .matcher(apiClientHeaderKey) 993 .matches()); 994 } 995 996 @Test listNamespacesExceptionTest2()997 public void listNamespacesExceptionTest2() throws Exception { 998 ApiException exception = 999 ApiExceptionFactory.createException( 1000 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1001 mockService.addException(exception); 1002 1003 try { 1004 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1005 client.listNamespaces(parent); 1006 Assert.fail("No exception raised"); 1007 } catch (InvalidArgumentException e) { 1008 // Expected exception. 1009 } 1010 } 1011 1012 @Test addDnsPeeringTest()1013 public void addDnsPeeringTest() throws Exception { 1014 AddDnsPeeringResponse expectedResponse = AddDnsPeeringResponse.newBuilder().build(); 1015 mockService.addResponse(expectedResponse); 1016 1017 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 1018 1019 AddDnsPeeringResponse actualResponse = client.addDnsPeering(parent); 1020 Assert.assertEquals(expectedResponse, actualResponse); 1021 1022 List<String> actualRequests = mockService.getRequestPaths(); 1023 Assert.assertEquals(1, actualRequests.size()); 1024 1025 String apiClientHeaderKey = 1026 mockService 1027 .getRequestHeaders() 1028 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1029 .iterator() 1030 .next(); 1031 Assert.assertTrue( 1032 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1033 .matcher(apiClientHeaderKey) 1034 .matches()); 1035 } 1036 1037 @Test addDnsPeeringExceptionTest()1038 public void addDnsPeeringExceptionTest() throws Exception { 1039 ApiException exception = 1040 ApiExceptionFactory.createException( 1041 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1042 mockService.addException(exception); 1043 1044 try { 1045 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 1046 client.addDnsPeering(parent); 1047 Assert.fail("No exception raised"); 1048 } catch (InvalidArgumentException e) { 1049 // Expected exception. 1050 } 1051 } 1052 1053 @Test addDnsPeeringTest2()1054 public void addDnsPeeringTest2() throws Exception { 1055 AddDnsPeeringResponse expectedResponse = AddDnsPeeringResponse.newBuilder().build(); 1056 mockService.addResponse(expectedResponse); 1057 1058 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1059 1060 AddDnsPeeringResponse actualResponse = client.addDnsPeering(parent); 1061 Assert.assertEquals(expectedResponse, actualResponse); 1062 1063 List<String> actualRequests = mockService.getRequestPaths(); 1064 Assert.assertEquals(1, actualRequests.size()); 1065 1066 String apiClientHeaderKey = 1067 mockService 1068 .getRequestHeaders() 1069 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1070 .iterator() 1071 .next(); 1072 Assert.assertTrue( 1073 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1074 .matcher(apiClientHeaderKey) 1075 .matches()); 1076 } 1077 1078 @Test addDnsPeeringExceptionTest2()1079 public void addDnsPeeringExceptionTest2() throws Exception { 1080 ApiException exception = 1081 ApiExceptionFactory.createException( 1082 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1083 mockService.addException(exception); 1084 1085 try { 1086 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1087 client.addDnsPeering(parent); 1088 Assert.fail("No exception raised"); 1089 } catch (InvalidArgumentException e) { 1090 // Expected exception. 1091 } 1092 } 1093 1094 @Test removeDnsPeeringTest()1095 public void removeDnsPeeringTest() throws Exception { 1096 RemoveDnsPeeringResponse expectedResponse = RemoveDnsPeeringResponse.newBuilder().build(); 1097 mockService.addResponse(expectedResponse); 1098 1099 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 1100 1101 RemoveDnsPeeringResponse actualResponse = client.removeDnsPeering(parent); 1102 Assert.assertEquals(expectedResponse, actualResponse); 1103 1104 List<String> actualRequests = mockService.getRequestPaths(); 1105 Assert.assertEquals(1, actualRequests.size()); 1106 1107 String apiClientHeaderKey = 1108 mockService 1109 .getRequestHeaders() 1110 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1111 .iterator() 1112 .next(); 1113 Assert.assertTrue( 1114 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1115 .matcher(apiClientHeaderKey) 1116 .matches()); 1117 } 1118 1119 @Test removeDnsPeeringExceptionTest()1120 public void removeDnsPeeringExceptionTest() throws Exception { 1121 ApiException exception = 1122 ApiExceptionFactory.createException( 1123 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1124 mockService.addException(exception); 1125 1126 try { 1127 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 1128 client.removeDnsPeering(parent); 1129 Assert.fail("No exception raised"); 1130 } catch (InvalidArgumentException e) { 1131 // Expected exception. 1132 } 1133 } 1134 1135 @Test removeDnsPeeringTest2()1136 public void removeDnsPeeringTest2() throws Exception { 1137 RemoveDnsPeeringResponse expectedResponse = RemoveDnsPeeringResponse.newBuilder().build(); 1138 mockService.addResponse(expectedResponse); 1139 1140 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1141 1142 RemoveDnsPeeringResponse actualResponse = client.removeDnsPeering(parent); 1143 Assert.assertEquals(expectedResponse, actualResponse); 1144 1145 List<String> actualRequests = mockService.getRequestPaths(); 1146 Assert.assertEquals(1, actualRequests.size()); 1147 1148 String apiClientHeaderKey = 1149 mockService 1150 .getRequestHeaders() 1151 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1152 .iterator() 1153 .next(); 1154 Assert.assertTrue( 1155 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1156 .matcher(apiClientHeaderKey) 1157 .matches()); 1158 } 1159 1160 @Test removeDnsPeeringExceptionTest2()1161 public void removeDnsPeeringExceptionTest2() throws Exception { 1162 ApiException exception = 1163 ApiExceptionFactory.createException( 1164 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1165 mockService.addException(exception); 1166 1167 try { 1168 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1169 client.removeDnsPeering(parent); 1170 Assert.fail("No exception raised"); 1171 } catch (InvalidArgumentException e) { 1172 // Expected exception. 1173 } 1174 } 1175 1176 @Test listDnsPeeringsTest()1177 public void listDnsPeeringsTest() throws Exception { 1178 DnsPeering responsesElement = DnsPeering.newBuilder().build(); 1179 ListDnsPeeringsResponse expectedResponse = 1180 ListDnsPeeringsResponse.newBuilder() 1181 .setNextPageToken("") 1182 .addAllDnsPeerings(Arrays.asList(responsesElement)) 1183 .build(); 1184 mockService.addResponse(expectedResponse); 1185 1186 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 1187 1188 ListDnsPeeringsPagedResponse pagedListResponse = client.listDnsPeerings(parent); 1189 1190 List<DnsPeering> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1191 1192 Assert.assertEquals(1, resources.size()); 1193 Assert.assertEquals(expectedResponse.getDnsPeeringsList().get(0), resources.get(0)); 1194 1195 List<String> actualRequests = mockService.getRequestPaths(); 1196 Assert.assertEquals(1, actualRequests.size()); 1197 1198 String apiClientHeaderKey = 1199 mockService 1200 .getRequestHeaders() 1201 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1202 .iterator() 1203 .next(); 1204 Assert.assertTrue( 1205 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1206 .matcher(apiClientHeaderKey) 1207 .matches()); 1208 } 1209 1210 @Test listDnsPeeringsExceptionTest()1211 public void listDnsPeeringsExceptionTest() throws Exception { 1212 ApiException exception = 1213 ApiExceptionFactory.createException( 1214 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1215 mockService.addException(exception); 1216 1217 try { 1218 InstanceName parent = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); 1219 client.listDnsPeerings(parent); 1220 Assert.fail("No exception raised"); 1221 } catch (InvalidArgumentException e) { 1222 // Expected exception. 1223 } 1224 } 1225 1226 @Test listDnsPeeringsTest2()1227 public void listDnsPeeringsTest2() throws Exception { 1228 DnsPeering responsesElement = DnsPeering.newBuilder().build(); 1229 ListDnsPeeringsResponse expectedResponse = 1230 ListDnsPeeringsResponse.newBuilder() 1231 .setNextPageToken("") 1232 .addAllDnsPeerings(Arrays.asList(responsesElement)) 1233 .build(); 1234 mockService.addResponse(expectedResponse); 1235 1236 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1237 1238 ListDnsPeeringsPagedResponse pagedListResponse = client.listDnsPeerings(parent); 1239 1240 List<DnsPeering> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1241 1242 Assert.assertEquals(1, resources.size()); 1243 Assert.assertEquals(expectedResponse.getDnsPeeringsList().get(0), resources.get(0)); 1244 1245 List<String> actualRequests = mockService.getRequestPaths(); 1246 Assert.assertEquals(1, actualRequests.size()); 1247 1248 String apiClientHeaderKey = 1249 mockService 1250 .getRequestHeaders() 1251 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 1252 .iterator() 1253 .next(); 1254 Assert.assertTrue( 1255 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 1256 .matcher(apiClientHeaderKey) 1257 .matches()); 1258 } 1259 1260 @Test listDnsPeeringsExceptionTest2()1261 public void listDnsPeeringsExceptionTest2() throws Exception { 1262 ApiException exception = 1263 ApiExceptionFactory.createException( 1264 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 1265 mockService.addException(exception); 1266 1267 try { 1268 String parent = "projects/project-5197/locations/location-5197/instances/instance-5197"; 1269 client.listDnsPeerings(parent); 1270 Assert.fail("No exception raised"); 1271 } catch (InvalidArgumentException e) { 1272 // Expected exception. 1273 } 1274 } 1275 } 1276