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.monitoring.v3; 18 19 import static com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServiceLevelObjectivesPagedResponse; 20 import static com.google.cloud.monitoring.v3.ServiceMonitoringServiceClient.ListServicesPagedResponse; 21 22 import com.google.api.gax.core.NoCredentialsProvider; 23 import com.google.api.gax.grpc.GaxGrpcProperties; 24 import com.google.api.gax.grpc.testing.LocalChannelProvider; 25 import com.google.api.gax.grpc.testing.MockGrpcService; 26 import com.google.api.gax.grpc.testing.MockServiceHelper; 27 import com.google.api.gax.rpc.ApiClientHeaderProvider; 28 import com.google.api.gax.rpc.InvalidArgumentException; 29 import com.google.common.collect.Lists; 30 import com.google.monitoring.v3.CreateServiceLevelObjectiveRequest; 31 import com.google.monitoring.v3.CreateServiceRequest; 32 import com.google.monitoring.v3.DeleteServiceLevelObjectiveRequest; 33 import com.google.monitoring.v3.DeleteServiceRequest; 34 import com.google.monitoring.v3.FolderName; 35 import com.google.monitoring.v3.GetServiceLevelObjectiveRequest; 36 import com.google.monitoring.v3.GetServiceRequest; 37 import com.google.monitoring.v3.ListServiceLevelObjectivesRequest; 38 import com.google.monitoring.v3.ListServiceLevelObjectivesResponse; 39 import com.google.monitoring.v3.ListServicesRequest; 40 import com.google.monitoring.v3.ListServicesResponse; 41 import com.google.monitoring.v3.OrganizationName; 42 import com.google.monitoring.v3.ProjectName; 43 import com.google.monitoring.v3.Service; 44 import com.google.monitoring.v3.ServiceLevelIndicator; 45 import com.google.monitoring.v3.ServiceLevelObjective; 46 import com.google.monitoring.v3.ServiceLevelObjectiveName; 47 import com.google.monitoring.v3.ServiceName; 48 import com.google.monitoring.v3.UpdateServiceLevelObjectiveRequest; 49 import com.google.monitoring.v3.UpdateServiceRequest; 50 import com.google.protobuf.AbstractMessage; 51 import com.google.protobuf.Empty; 52 import io.grpc.StatusRuntimeException; 53 import java.io.IOException; 54 import java.util.Arrays; 55 import java.util.HashMap; 56 import java.util.List; 57 import java.util.UUID; 58 import javax.annotation.Generated; 59 import org.junit.After; 60 import org.junit.AfterClass; 61 import org.junit.Assert; 62 import org.junit.Before; 63 import org.junit.BeforeClass; 64 import org.junit.Test; 65 66 @Generated("by gapic-generator-java") 67 public class ServiceMonitoringServiceClientTest { 68 private static MockServiceHelper mockServiceHelper; 69 private static MockServiceMonitoringService mockServiceMonitoringService; 70 private LocalChannelProvider channelProvider; 71 private ServiceMonitoringServiceClient client; 72 73 @BeforeClass startStaticServer()74 public static void startStaticServer() { 75 mockServiceMonitoringService = new MockServiceMonitoringService(); 76 mockServiceHelper = 77 new MockServiceHelper( 78 UUID.randomUUID().toString(), 79 Arrays.<MockGrpcService>asList(mockServiceMonitoringService)); 80 mockServiceHelper.start(); 81 } 82 83 @AfterClass stopServer()84 public static void stopServer() { 85 mockServiceHelper.stop(); 86 } 87 88 @Before setUp()89 public void setUp() throws IOException { 90 mockServiceHelper.reset(); 91 channelProvider = mockServiceHelper.createChannelProvider(); 92 ServiceMonitoringServiceSettings settings = 93 ServiceMonitoringServiceSettings.newBuilder() 94 .setTransportChannelProvider(channelProvider) 95 .setCredentialsProvider(NoCredentialsProvider.create()) 96 .build(); 97 client = ServiceMonitoringServiceClient.create(settings); 98 } 99 100 @After tearDown()101 public void tearDown() throws Exception { 102 client.close(); 103 } 104 105 @Test createServiceTest()106 public void createServiceTest() throws Exception { 107 Service expectedResponse = 108 Service.newBuilder() 109 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 110 .setDisplayName("displayName1714148973") 111 .setTelemetry(Service.Telemetry.newBuilder().build()) 112 .putAllUserLabels(new HashMap<String, String>()) 113 .build(); 114 mockServiceMonitoringService.addResponse(expectedResponse); 115 116 FolderName parent = FolderName.of("[FOLDER]"); 117 Service service = Service.newBuilder().build(); 118 119 Service actualResponse = client.createService(parent, service); 120 Assert.assertEquals(expectedResponse, actualResponse); 121 122 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 123 Assert.assertEquals(1, actualRequests.size()); 124 CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0)); 125 126 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 127 Assert.assertEquals(service, actualRequest.getService()); 128 Assert.assertTrue( 129 channelProvider.isHeaderSent( 130 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 131 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 132 } 133 134 @Test createServiceExceptionTest()135 public void createServiceExceptionTest() throws Exception { 136 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 137 mockServiceMonitoringService.addException(exception); 138 139 try { 140 FolderName parent = FolderName.of("[FOLDER]"); 141 Service service = Service.newBuilder().build(); 142 client.createService(parent, service); 143 Assert.fail("No exception raised"); 144 } catch (InvalidArgumentException e) { 145 // Expected exception. 146 } 147 } 148 149 @Test createServiceTest2()150 public void createServiceTest2() throws Exception { 151 Service expectedResponse = 152 Service.newBuilder() 153 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 154 .setDisplayName("displayName1714148973") 155 .setTelemetry(Service.Telemetry.newBuilder().build()) 156 .putAllUserLabels(new HashMap<String, String>()) 157 .build(); 158 mockServiceMonitoringService.addResponse(expectedResponse); 159 160 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 161 Service service = Service.newBuilder().build(); 162 163 Service actualResponse = client.createService(parent, service); 164 Assert.assertEquals(expectedResponse, actualResponse); 165 166 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 167 Assert.assertEquals(1, actualRequests.size()); 168 CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0)); 169 170 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 171 Assert.assertEquals(service, actualRequest.getService()); 172 Assert.assertTrue( 173 channelProvider.isHeaderSent( 174 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 175 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 176 } 177 178 @Test createServiceExceptionTest2()179 public void createServiceExceptionTest2() throws Exception { 180 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 181 mockServiceMonitoringService.addException(exception); 182 183 try { 184 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 185 Service service = Service.newBuilder().build(); 186 client.createService(parent, service); 187 Assert.fail("No exception raised"); 188 } catch (InvalidArgumentException e) { 189 // Expected exception. 190 } 191 } 192 193 @Test createServiceTest3()194 public void createServiceTest3() throws Exception { 195 Service expectedResponse = 196 Service.newBuilder() 197 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 198 .setDisplayName("displayName1714148973") 199 .setTelemetry(Service.Telemetry.newBuilder().build()) 200 .putAllUserLabels(new HashMap<String, String>()) 201 .build(); 202 mockServiceMonitoringService.addResponse(expectedResponse); 203 204 ProjectName parent = ProjectName.of("[PROJECT]"); 205 Service service = Service.newBuilder().build(); 206 207 Service actualResponse = client.createService(parent, service); 208 Assert.assertEquals(expectedResponse, actualResponse); 209 210 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 211 Assert.assertEquals(1, actualRequests.size()); 212 CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0)); 213 214 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 215 Assert.assertEquals(service, actualRequest.getService()); 216 Assert.assertTrue( 217 channelProvider.isHeaderSent( 218 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 219 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 220 } 221 222 @Test createServiceExceptionTest3()223 public void createServiceExceptionTest3() throws Exception { 224 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 225 mockServiceMonitoringService.addException(exception); 226 227 try { 228 ProjectName parent = ProjectName.of("[PROJECT]"); 229 Service service = Service.newBuilder().build(); 230 client.createService(parent, service); 231 Assert.fail("No exception raised"); 232 } catch (InvalidArgumentException e) { 233 // Expected exception. 234 } 235 } 236 237 @Test createServiceTest4()238 public void createServiceTest4() throws Exception { 239 Service expectedResponse = 240 Service.newBuilder() 241 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 242 .setDisplayName("displayName1714148973") 243 .setTelemetry(Service.Telemetry.newBuilder().build()) 244 .putAllUserLabels(new HashMap<String, String>()) 245 .build(); 246 mockServiceMonitoringService.addResponse(expectedResponse); 247 248 String parent = "parent-995424086"; 249 Service service = Service.newBuilder().build(); 250 251 Service actualResponse = client.createService(parent, service); 252 Assert.assertEquals(expectedResponse, actualResponse); 253 254 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 255 Assert.assertEquals(1, actualRequests.size()); 256 CreateServiceRequest actualRequest = ((CreateServiceRequest) actualRequests.get(0)); 257 258 Assert.assertEquals(parent, actualRequest.getParent()); 259 Assert.assertEquals(service, actualRequest.getService()); 260 Assert.assertTrue( 261 channelProvider.isHeaderSent( 262 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 263 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 264 } 265 266 @Test createServiceExceptionTest4()267 public void createServiceExceptionTest4() throws Exception { 268 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 269 mockServiceMonitoringService.addException(exception); 270 271 try { 272 String parent = "parent-995424086"; 273 Service service = Service.newBuilder().build(); 274 client.createService(parent, service); 275 Assert.fail("No exception raised"); 276 } catch (InvalidArgumentException e) { 277 // Expected exception. 278 } 279 } 280 281 @Test getServiceTest()282 public void getServiceTest() throws Exception { 283 Service expectedResponse = 284 Service.newBuilder() 285 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 286 .setDisplayName("displayName1714148973") 287 .setTelemetry(Service.Telemetry.newBuilder().build()) 288 .putAllUserLabels(new HashMap<String, String>()) 289 .build(); 290 mockServiceMonitoringService.addResponse(expectedResponse); 291 292 ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 293 294 Service actualResponse = client.getService(name); 295 Assert.assertEquals(expectedResponse, actualResponse); 296 297 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 298 Assert.assertEquals(1, actualRequests.size()); 299 GetServiceRequest actualRequest = ((GetServiceRequest) actualRequests.get(0)); 300 301 Assert.assertEquals(name.toString(), actualRequest.getName()); 302 Assert.assertTrue( 303 channelProvider.isHeaderSent( 304 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 305 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 306 } 307 308 @Test getServiceExceptionTest()309 public void getServiceExceptionTest() throws Exception { 310 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 311 mockServiceMonitoringService.addException(exception); 312 313 try { 314 ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 315 client.getService(name); 316 Assert.fail("No exception raised"); 317 } catch (InvalidArgumentException e) { 318 // Expected exception. 319 } 320 } 321 322 @Test getServiceTest2()323 public void getServiceTest2() throws Exception { 324 Service expectedResponse = 325 Service.newBuilder() 326 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 327 .setDisplayName("displayName1714148973") 328 .setTelemetry(Service.Telemetry.newBuilder().build()) 329 .putAllUserLabels(new HashMap<String, String>()) 330 .build(); 331 mockServiceMonitoringService.addResponse(expectedResponse); 332 333 String name = "name3373707"; 334 335 Service actualResponse = client.getService(name); 336 Assert.assertEquals(expectedResponse, actualResponse); 337 338 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 339 Assert.assertEquals(1, actualRequests.size()); 340 GetServiceRequest actualRequest = ((GetServiceRequest) actualRequests.get(0)); 341 342 Assert.assertEquals(name, actualRequest.getName()); 343 Assert.assertTrue( 344 channelProvider.isHeaderSent( 345 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 346 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 347 } 348 349 @Test getServiceExceptionTest2()350 public void getServiceExceptionTest2() throws Exception { 351 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 352 mockServiceMonitoringService.addException(exception); 353 354 try { 355 String name = "name3373707"; 356 client.getService(name); 357 Assert.fail("No exception raised"); 358 } catch (InvalidArgumentException e) { 359 // Expected exception. 360 } 361 } 362 363 @Test listServicesTest()364 public void listServicesTest() throws Exception { 365 Service responsesElement = Service.newBuilder().build(); 366 ListServicesResponse expectedResponse = 367 ListServicesResponse.newBuilder() 368 .setNextPageToken("") 369 .addAllServices(Arrays.asList(responsesElement)) 370 .build(); 371 mockServiceMonitoringService.addResponse(expectedResponse); 372 373 FolderName parent = FolderName.of("[FOLDER]"); 374 375 ListServicesPagedResponse pagedListResponse = client.listServices(parent); 376 377 List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 378 379 Assert.assertEquals(1, resources.size()); 380 Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); 381 382 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 383 Assert.assertEquals(1, actualRequests.size()); 384 ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0)); 385 386 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 387 Assert.assertTrue( 388 channelProvider.isHeaderSent( 389 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 390 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 391 } 392 393 @Test listServicesExceptionTest()394 public void listServicesExceptionTest() throws Exception { 395 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 396 mockServiceMonitoringService.addException(exception); 397 398 try { 399 FolderName parent = FolderName.of("[FOLDER]"); 400 client.listServices(parent); 401 Assert.fail("No exception raised"); 402 } catch (InvalidArgumentException e) { 403 // Expected exception. 404 } 405 } 406 407 @Test listServicesTest2()408 public void listServicesTest2() throws Exception { 409 Service responsesElement = Service.newBuilder().build(); 410 ListServicesResponse expectedResponse = 411 ListServicesResponse.newBuilder() 412 .setNextPageToken("") 413 .addAllServices(Arrays.asList(responsesElement)) 414 .build(); 415 mockServiceMonitoringService.addResponse(expectedResponse); 416 417 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 418 419 ListServicesPagedResponse pagedListResponse = client.listServices(parent); 420 421 List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 422 423 Assert.assertEquals(1, resources.size()); 424 Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); 425 426 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 427 Assert.assertEquals(1, actualRequests.size()); 428 ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0)); 429 430 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 431 Assert.assertTrue( 432 channelProvider.isHeaderSent( 433 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 434 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 435 } 436 437 @Test listServicesExceptionTest2()438 public void listServicesExceptionTest2() throws Exception { 439 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 440 mockServiceMonitoringService.addException(exception); 441 442 try { 443 OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 444 client.listServices(parent); 445 Assert.fail("No exception raised"); 446 } catch (InvalidArgumentException e) { 447 // Expected exception. 448 } 449 } 450 451 @Test listServicesTest3()452 public void listServicesTest3() throws Exception { 453 Service responsesElement = Service.newBuilder().build(); 454 ListServicesResponse expectedResponse = 455 ListServicesResponse.newBuilder() 456 .setNextPageToken("") 457 .addAllServices(Arrays.asList(responsesElement)) 458 .build(); 459 mockServiceMonitoringService.addResponse(expectedResponse); 460 461 ProjectName parent = ProjectName.of("[PROJECT]"); 462 463 ListServicesPagedResponse pagedListResponse = client.listServices(parent); 464 465 List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 466 467 Assert.assertEquals(1, resources.size()); 468 Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); 469 470 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 471 Assert.assertEquals(1, actualRequests.size()); 472 ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0)); 473 474 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 475 Assert.assertTrue( 476 channelProvider.isHeaderSent( 477 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 478 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 479 } 480 481 @Test listServicesExceptionTest3()482 public void listServicesExceptionTest3() throws Exception { 483 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 484 mockServiceMonitoringService.addException(exception); 485 486 try { 487 ProjectName parent = ProjectName.of("[PROJECT]"); 488 client.listServices(parent); 489 Assert.fail("No exception raised"); 490 } catch (InvalidArgumentException e) { 491 // Expected exception. 492 } 493 } 494 495 @Test listServicesTest4()496 public void listServicesTest4() throws Exception { 497 Service responsesElement = Service.newBuilder().build(); 498 ListServicesResponse expectedResponse = 499 ListServicesResponse.newBuilder() 500 .setNextPageToken("") 501 .addAllServices(Arrays.asList(responsesElement)) 502 .build(); 503 mockServiceMonitoringService.addResponse(expectedResponse); 504 505 String parent = "parent-995424086"; 506 507 ListServicesPagedResponse pagedListResponse = client.listServices(parent); 508 509 List<Service> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 510 511 Assert.assertEquals(1, resources.size()); 512 Assert.assertEquals(expectedResponse.getServicesList().get(0), resources.get(0)); 513 514 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 515 Assert.assertEquals(1, actualRequests.size()); 516 ListServicesRequest actualRequest = ((ListServicesRequest) actualRequests.get(0)); 517 518 Assert.assertEquals(parent, actualRequest.getParent()); 519 Assert.assertTrue( 520 channelProvider.isHeaderSent( 521 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 522 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 523 } 524 525 @Test listServicesExceptionTest4()526 public void listServicesExceptionTest4() throws Exception { 527 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 528 mockServiceMonitoringService.addException(exception); 529 530 try { 531 String parent = "parent-995424086"; 532 client.listServices(parent); 533 Assert.fail("No exception raised"); 534 } catch (InvalidArgumentException e) { 535 // Expected exception. 536 } 537 } 538 539 @Test updateServiceTest()540 public void updateServiceTest() throws Exception { 541 Service expectedResponse = 542 Service.newBuilder() 543 .setName(ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]").toString()) 544 .setDisplayName("displayName1714148973") 545 .setTelemetry(Service.Telemetry.newBuilder().build()) 546 .putAllUserLabels(new HashMap<String, String>()) 547 .build(); 548 mockServiceMonitoringService.addResponse(expectedResponse); 549 550 Service service = Service.newBuilder().build(); 551 552 Service actualResponse = client.updateService(service); 553 Assert.assertEquals(expectedResponse, actualResponse); 554 555 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 556 Assert.assertEquals(1, actualRequests.size()); 557 UpdateServiceRequest actualRequest = ((UpdateServiceRequest) actualRequests.get(0)); 558 559 Assert.assertEquals(service, actualRequest.getService()); 560 Assert.assertTrue( 561 channelProvider.isHeaderSent( 562 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 563 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 564 } 565 566 @Test updateServiceExceptionTest()567 public void updateServiceExceptionTest() throws Exception { 568 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 569 mockServiceMonitoringService.addException(exception); 570 571 try { 572 Service service = Service.newBuilder().build(); 573 client.updateService(service); 574 Assert.fail("No exception raised"); 575 } catch (InvalidArgumentException e) { 576 // Expected exception. 577 } 578 } 579 580 @Test deleteServiceTest()581 public void deleteServiceTest() throws Exception { 582 Empty expectedResponse = Empty.newBuilder().build(); 583 mockServiceMonitoringService.addResponse(expectedResponse); 584 585 ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 586 587 client.deleteService(name); 588 589 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 590 Assert.assertEquals(1, actualRequests.size()); 591 DeleteServiceRequest actualRequest = ((DeleteServiceRequest) actualRequests.get(0)); 592 593 Assert.assertEquals(name.toString(), actualRequest.getName()); 594 Assert.assertTrue( 595 channelProvider.isHeaderSent( 596 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 597 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 598 } 599 600 @Test deleteServiceExceptionTest()601 public void deleteServiceExceptionTest() throws Exception { 602 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 603 mockServiceMonitoringService.addException(exception); 604 605 try { 606 ServiceName name = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 607 client.deleteService(name); 608 Assert.fail("No exception raised"); 609 } catch (InvalidArgumentException e) { 610 // Expected exception. 611 } 612 } 613 614 @Test deleteServiceTest2()615 public void deleteServiceTest2() throws Exception { 616 Empty expectedResponse = Empty.newBuilder().build(); 617 mockServiceMonitoringService.addResponse(expectedResponse); 618 619 String name = "name3373707"; 620 621 client.deleteService(name); 622 623 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 624 Assert.assertEquals(1, actualRequests.size()); 625 DeleteServiceRequest actualRequest = ((DeleteServiceRequest) actualRequests.get(0)); 626 627 Assert.assertEquals(name, actualRequest.getName()); 628 Assert.assertTrue( 629 channelProvider.isHeaderSent( 630 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 631 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 632 } 633 634 @Test deleteServiceExceptionTest2()635 public void deleteServiceExceptionTest2() throws Exception { 636 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 637 mockServiceMonitoringService.addException(exception); 638 639 try { 640 String name = "name3373707"; 641 client.deleteService(name); 642 Assert.fail("No exception raised"); 643 } catch (InvalidArgumentException e) { 644 // Expected exception. 645 } 646 } 647 648 @Test createServiceLevelObjectiveTest()649 public void createServiceLevelObjectiveTest() throws Exception { 650 ServiceLevelObjective expectedResponse = 651 ServiceLevelObjective.newBuilder() 652 .setName( 653 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 654 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]") 655 .toString()) 656 .setDisplayName("displayName1714148973") 657 .setServiceLevelIndicator(ServiceLevelIndicator.newBuilder().build()) 658 .setGoal(3178259) 659 .putAllUserLabels(new HashMap<String, String>()) 660 .build(); 661 mockServiceMonitoringService.addResponse(expectedResponse); 662 663 ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 664 ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build(); 665 666 ServiceLevelObjective actualResponse = 667 client.createServiceLevelObjective(parent, serviceLevelObjective); 668 Assert.assertEquals(expectedResponse, actualResponse); 669 670 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 671 Assert.assertEquals(1, actualRequests.size()); 672 CreateServiceLevelObjectiveRequest actualRequest = 673 ((CreateServiceLevelObjectiveRequest) actualRequests.get(0)); 674 675 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 676 Assert.assertEquals(serviceLevelObjective, actualRequest.getServiceLevelObjective()); 677 Assert.assertTrue( 678 channelProvider.isHeaderSent( 679 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 680 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 681 } 682 683 @Test createServiceLevelObjectiveExceptionTest()684 public void createServiceLevelObjectiveExceptionTest() throws Exception { 685 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 686 mockServiceMonitoringService.addException(exception); 687 688 try { 689 ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 690 ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build(); 691 client.createServiceLevelObjective(parent, serviceLevelObjective); 692 Assert.fail("No exception raised"); 693 } catch (InvalidArgumentException e) { 694 // Expected exception. 695 } 696 } 697 698 @Test createServiceLevelObjectiveTest2()699 public void createServiceLevelObjectiveTest2() throws Exception { 700 ServiceLevelObjective expectedResponse = 701 ServiceLevelObjective.newBuilder() 702 .setName( 703 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 704 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]") 705 .toString()) 706 .setDisplayName("displayName1714148973") 707 .setServiceLevelIndicator(ServiceLevelIndicator.newBuilder().build()) 708 .setGoal(3178259) 709 .putAllUserLabels(new HashMap<String, String>()) 710 .build(); 711 mockServiceMonitoringService.addResponse(expectedResponse); 712 713 String parent = "parent-995424086"; 714 ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build(); 715 716 ServiceLevelObjective actualResponse = 717 client.createServiceLevelObjective(parent, serviceLevelObjective); 718 Assert.assertEquals(expectedResponse, actualResponse); 719 720 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 721 Assert.assertEquals(1, actualRequests.size()); 722 CreateServiceLevelObjectiveRequest actualRequest = 723 ((CreateServiceLevelObjectiveRequest) actualRequests.get(0)); 724 725 Assert.assertEquals(parent, actualRequest.getParent()); 726 Assert.assertEquals(serviceLevelObjective, actualRequest.getServiceLevelObjective()); 727 Assert.assertTrue( 728 channelProvider.isHeaderSent( 729 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 730 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 731 } 732 733 @Test createServiceLevelObjectiveExceptionTest2()734 public void createServiceLevelObjectiveExceptionTest2() throws Exception { 735 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 736 mockServiceMonitoringService.addException(exception); 737 738 try { 739 String parent = "parent-995424086"; 740 ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build(); 741 client.createServiceLevelObjective(parent, serviceLevelObjective); 742 Assert.fail("No exception raised"); 743 } catch (InvalidArgumentException e) { 744 // Expected exception. 745 } 746 } 747 748 @Test getServiceLevelObjectiveTest()749 public void getServiceLevelObjectiveTest() throws Exception { 750 ServiceLevelObjective expectedResponse = 751 ServiceLevelObjective.newBuilder() 752 .setName( 753 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 754 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]") 755 .toString()) 756 .setDisplayName("displayName1714148973") 757 .setServiceLevelIndicator(ServiceLevelIndicator.newBuilder().build()) 758 .setGoal(3178259) 759 .putAllUserLabels(new HashMap<String, String>()) 760 .build(); 761 mockServiceMonitoringService.addResponse(expectedResponse); 762 763 ServiceLevelObjectiveName name = 764 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 765 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]"); 766 767 ServiceLevelObjective actualResponse = client.getServiceLevelObjective(name); 768 Assert.assertEquals(expectedResponse, actualResponse); 769 770 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 771 Assert.assertEquals(1, actualRequests.size()); 772 GetServiceLevelObjectiveRequest actualRequest = 773 ((GetServiceLevelObjectiveRequest) actualRequests.get(0)); 774 775 Assert.assertEquals(name.toString(), actualRequest.getName()); 776 Assert.assertTrue( 777 channelProvider.isHeaderSent( 778 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 779 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 780 } 781 782 @Test getServiceLevelObjectiveExceptionTest()783 public void getServiceLevelObjectiveExceptionTest() throws Exception { 784 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 785 mockServiceMonitoringService.addException(exception); 786 787 try { 788 ServiceLevelObjectiveName name = 789 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 790 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]"); 791 client.getServiceLevelObjective(name); 792 Assert.fail("No exception raised"); 793 } catch (InvalidArgumentException e) { 794 // Expected exception. 795 } 796 } 797 798 @Test getServiceLevelObjectiveTest2()799 public void getServiceLevelObjectiveTest2() throws Exception { 800 ServiceLevelObjective expectedResponse = 801 ServiceLevelObjective.newBuilder() 802 .setName( 803 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 804 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]") 805 .toString()) 806 .setDisplayName("displayName1714148973") 807 .setServiceLevelIndicator(ServiceLevelIndicator.newBuilder().build()) 808 .setGoal(3178259) 809 .putAllUserLabels(new HashMap<String, String>()) 810 .build(); 811 mockServiceMonitoringService.addResponse(expectedResponse); 812 813 String name = "name3373707"; 814 815 ServiceLevelObjective actualResponse = client.getServiceLevelObjective(name); 816 Assert.assertEquals(expectedResponse, actualResponse); 817 818 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 819 Assert.assertEquals(1, actualRequests.size()); 820 GetServiceLevelObjectiveRequest actualRequest = 821 ((GetServiceLevelObjectiveRequest) actualRequests.get(0)); 822 823 Assert.assertEquals(name, actualRequest.getName()); 824 Assert.assertTrue( 825 channelProvider.isHeaderSent( 826 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 827 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 828 } 829 830 @Test getServiceLevelObjectiveExceptionTest2()831 public void getServiceLevelObjectiveExceptionTest2() throws Exception { 832 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 833 mockServiceMonitoringService.addException(exception); 834 835 try { 836 String name = "name3373707"; 837 client.getServiceLevelObjective(name); 838 Assert.fail("No exception raised"); 839 } catch (InvalidArgumentException e) { 840 // Expected exception. 841 } 842 } 843 844 @Test listServiceLevelObjectivesTest()845 public void listServiceLevelObjectivesTest() throws Exception { 846 ServiceLevelObjective responsesElement = ServiceLevelObjective.newBuilder().build(); 847 ListServiceLevelObjectivesResponse expectedResponse = 848 ListServiceLevelObjectivesResponse.newBuilder() 849 .setNextPageToken("") 850 .addAllServiceLevelObjectives(Arrays.asList(responsesElement)) 851 .build(); 852 mockServiceMonitoringService.addResponse(expectedResponse); 853 854 ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 855 856 ListServiceLevelObjectivesPagedResponse pagedListResponse = 857 client.listServiceLevelObjectives(parent); 858 859 List<ServiceLevelObjective> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 860 861 Assert.assertEquals(1, resources.size()); 862 Assert.assertEquals(expectedResponse.getServiceLevelObjectivesList().get(0), resources.get(0)); 863 864 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 865 Assert.assertEquals(1, actualRequests.size()); 866 ListServiceLevelObjectivesRequest actualRequest = 867 ((ListServiceLevelObjectivesRequest) actualRequests.get(0)); 868 869 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 870 Assert.assertTrue( 871 channelProvider.isHeaderSent( 872 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 873 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 874 } 875 876 @Test listServiceLevelObjectivesExceptionTest()877 public void listServiceLevelObjectivesExceptionTest() throws Exception { 878 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 879 mockServiceMonitoringService.addException(exception); 880 881 try { 882 ServiceName parent = ServiceName.ofProjectServiceName("[PROJECT]", "[SERVICE]"); 883 client.listServiceLevelObjectives(parent); 884 Assert.fail("No exception raised"); 885 } catch (InvalidArgumentException e) { 886 // Expected exception. 887 } 888 } 889 890 @Test listServiceLevelObjectivesTest2()891 public void listServiceLevelObjectivesTest2() throws Exception { 892 ServiceLevelObjective responsesElement = ServiceLevelObjective.newBuilder().build(); 893 ListServiceLevelObjectivesResponse expectedResponse = 894 ListServiceLevelObjectivesResponse.newBuilder() 895 .setNextPageToken("") 896 .addAllServiceLevelObjectives(Arrays.asList(responsesElement)) 897 .build(); 898 mockServiceMonitoringService.addResponse(expectedResponse); 899 900 String parent = "parent-995424086"; 901 902 ListServiceLevelObjectivesPagedResponse pagedListResponse = 903 client.listServiceLevelObjectives(parent); 904 905 List<ServiceLevelObjective> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 906 907 Assert.assertEquals(1, resources.size()); 908 Assert.assertEquals(expectedResponse.getServiceLevelObjectivesList().get(0), resources.get(0)); 909 910 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 911 Assert.assertEquals(1, actualRequests.size()); 912 ListServiceLevelObjectivesRequest actualRequest = 913 ((ListServiceLevelObjectivesRequest) actualRequests.get(0)); 914 915 Assert.assertEquals(parent, actualRequest.getParent()); 916 Assert.assertTrue( 917 channelProvider.isHeaderSent( 918 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 919 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 920 } 921 922 @Test listServiceLevelObjectivesExceptionTest2()923 public void listServiceLevelObjectivesExceptionTest2() throws Exception { 924 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 925 mockServiceMonitoringService.addException(exception); 926 927 try { 928 String parent = "parent-995424086"; 929 client.listServiceLevelObjectives(parent); 930 Assert.fail("No exception raised"); 931 } catch (InvalidArgumentException e) { 932 // Expected exception. 933 } 934 } 935 936 @Test updateServiceLevelObjectiveTest()937 public void updateServiceLevelObjectiveTest() throws Exception { 938 ServiceLevelObjective expectedResponse = 939 ServiceLevelObjective.newBuilder() 940 .setName( 941 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 942 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]") 943 .toString()) 944 .setDisplayName("displayName1714148973") 945 .setServiceLevelIndicator(ServiceLevelIndicator.newBuilder().build()) 946 .setGoal(3178259) 947 .putAllUserLabels(new HashMap<String, String>()) 948 .build(); 949 mockServiceMonitoringService.addResponse(expectedResponse); 950 951 ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build(); 952 953 ServiceLevelObjective actualResponse = 954 client.updateServiceLevelObjective(serviceLevelObjective); 955 Assert.assertEquals(expectedResponse, actualResponse); 956 957 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 958 Assert.assertEquals(1, actualRequests.size()); 959 UpdateServiceLevelObjectiveRequest actualRequest = 960 ((UpdateServiceLevelObjectiveRequest) actualRequests.get(0)); 961 962 Assert.assertEquals(serviceLevelObjective, actualRequest.getServiceLevelObjective()); 963 Assert.assertTrue( 964 channelProvider.isHeaderSent( 965 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 966 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 967 } 968 969 @Test updateServiceLevelObjectiveExceptionTest()970 public void updateServiceLevelObjectiveExceptionTest() throws Exception { 971 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 972 mockServiceMonitoringService.addException(exception); 973 974 try { 975 ServiceLevelObjective serviceLevelObjective = ServiceLevelObjective.newBuilder().build(); 976 client.updateServiceLevelObjective(serviceLevelObjective); 977 Assert.fail("No exception raised"); 978 } catch (InvalidArgumentException e) { 979 // Expected exception. 980 } 981 } 982 983 @Test deleteServiceLevelObjectiveTest()984 public void deleteServiceLevelObjectiveTest() throws Exception { 985 Empty expectedResponse = Empty.newBuilder().build(); 986 mockServiceMonitoringService.addResponse(expectedResponse); 987 988 ServiceLevelObjectiveName name = 989 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 990 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]"); 991 992 client.deleteServiceLevelObjective(name); 993 994 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 995 Assert.assertEquals(1, actualRequests.size()); 996 DeleteServiceLevelObjectiveRequest actualRequest = 997 ((DeleteServiceLevelObjectiveRequest) actualRequests.get(0)); 998 999 Assert.assertEquals(name.toString(), actualRequest.getName()); 1000 Assert.assertTrue( 1001 channelProvider.isHeaderSent( 1002 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1003 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1004 } 1005 1006 @Test deleteServiceLevelObjectiveExceptionTest()1007 public void deleteServiceLevelObjectiveExceptionTest() throws Exception { 1008 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1009 mockServiceMonitoringService.addException(exception); 1010 1011 try { 1012 ServiceLevelObjectiveName name = 1013 ServiceLevelObjectiveName.ofProjectServiceServiceLevelObjectiveName( 1014 "[PROJECT]", "[SERVICE]", "[SERVICE_LEVEL_OBJECTIVE]"); 1015 client.deleteServiceLevelObjective(name); 1016 Assert.fail("No exception raised"); 1017 } catch (InvalidArgumentException e) { 1018 // Expected exception. 1019 } 1020 } 1021 1022 @Test deleteServiceLevelObjectiveTest2()1023 public void deleteServiceLevelObjectiveTest2() throws Exception { 1024 Empty expectedResponse = Empty.newBuilder().build(); 1025 mockServiceMonitoringService.addResponse(expectedResponse); 1026 1027 String name = "name3373707"; 1028 1029 client.deleteServiceLevelObjective(name); 1030 1031 List<AbstractMessage> actualRequests = mockServiceMonitoringService.getRequests(); 1032 Assert.assertEquals(1, actualRequests.size()); 1033 DeleteServiceLevelObjectiveRequest actualRequest = 1034 ((DeleteServiceLevelObjectiveRequest) actualRequests.get(0)); 1035 1036 Assert.assertEquals(name, actualRequest.getName()); 1037 Assert.assertTrue( 1038 channelProvider.isHeaderSent( 1039 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1040 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1041 } 1042 1043 @Test deleteServiceLevelObjectiveExceptionTest2()1044 public void deleteServiceLevelObjectiveExceptionTest2() throws Exception { 1045 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1046 mockServiceMonitoringService.addException(exception); 1047 1048 try { 1049 String name = "name3373707"; 1050 client.deleteServiceLevelObjective(name); 1051 Assert.fail("No exception raised"); 1052 } catch (InvalidArgumentException e) { 1053 // Expected exception. 1054 } 1055 } 1056 } 1057