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.eventarc.v1; 18 19 import static com.google.cloud.eventarc.v1.EventarcClient.ListChannelConnectionsPagedResponse; 20 import static com.google.cloud.eventarc.v1.EventarcClient.ListChannelsPagedResponse; 21 import static com.google.cloud.eventarc.v1.EventarcClient.ListLocationsPagedResponse; 22 import static com.google.cloud.eventarc.v1.EventarcClient.ListProvidersPagedResponse; 23 import static com.google.cloud.eventarc.v1.EventarcClient.ListTriggersPagedResponse; 24 25 import com.google.api.gax.core.NoCredentialsProvider; 26 import com.google.api.gax.grpc.GaxGrpcProperties; 27 import com.google.api.gax.grpc.testing.LocalChannelProvider; 28 import com.google.api.gax.grpc.testing.MockGrpcService; 29 import com.google.api.gax.grpc.testing.MockServiceHelper; 30 import com.google.api.gax.rpc.ApiClientHeaderProvider; 31 import com.google.api.gax.rpc.InvalidArgumentException; 32 import com.google.api.gax.rpc.StatusCode; 33 import com.google.cloud.location.GetLocationRequest; 34 import com.google.cloud.location.ListLocationsRequest; 35 import com.google.cloud.location.ListLocationsResponse; 36 import com.google.cloud.location.Location; 37 import com.google.common.collect.Lists; 38 import com.google.iam.v1.AuditConfig; 39 import com.google.iam.v1.Binding; 40 import com.google.iam.v1.GetIamPolicyRequest; 41 import com.google.iam.v1.GetPolicyOptions; 42 import com.google.iam.v1.Policy; 43 import com.google.iam.v1.SetIamPolicyRequest; 44 import com.google.iam.v1.TestIamPermissionsRequest; 45 import com.google.iam.v1.TestIamPermissionsResponse; 46 import com.google.longrunning.Operation; 47 import com.google.protobuf.AbstractMessage; 48 import com.google.protobuf.Any; 49 import com.google.protobuf.ByteString; 50 import com.google.protobuf.FieldMask; 51 import com.google.protobuf.Timestamp; 52 import io.grpc.StatusRuntimeException; 53 import java.io.IOException; 54 import java.util.ArrayList; 55 import java.util.Arrays; 56 import java.util.HashMap; 57 import java.util.List; 58 import java.util.UUID; 59 import java.util.concurrent.ExecutionException; 60 import javax.annotation.Generated; 61 import org.junit.After; 62 import org.junit.AfterClass; 63 import org.junit.Assert; 64 import org.junit.Before; 65 import org.junit.BeforeClass; 66 import org.junit.Test; 67 68 @Generated("by gapic-generator-java") 69 public class EventarcClientTest { 70 private static MockEventarc mockEventarc; 71 private static MockIAMPolicy mockIAMPolicy; 72 private static MockLocations mockLocations; 73 private static MockServiceHelper mockServiceHelper; 74 private LocalChannelProvider channelProvider; 75 private EventarcClient client; 76 77 @BeforeClass startStaticServer()78 public static void startStaticServer() { 79 mockEventarc = new MockEventarc(); 80 mockLocations = new MockLocations(); 81 mockIAMPolicy = new MockIAMPolicy(); 82 mockServiceHelper = 83 new MockServiceHelper( 84 UUID.randomUUID().toString(), 85 Arrays.<MockGrpcService>asList(mockEventarc, mockLocations, mockIAMPolicy)); 86 mockServiceHelper.start(); 87 } 88 89 @AfterClass stopServer()90 public static void stopServer() { 91 mockServiceHelper.stop(); 92 } 93 94 @Before setUp()95 public void setUp() throws IOException { 96 mockServiceHelper.reset(); 97 channelProvider = mockServiceHelper.createChannelProvider(); 98 EventarcSettings settings = 99 EventarcSettings.newBuilder() 100 .setTransportChannelProvider(channelProvider) 101 .setCredentialsProvider(NoCredentialsProvider.create()) 102 .build(); 103 client = EventarcClient.create(settings); 104 } 105 106 @After tearDown()107 public void tearDown() throws Exception { 108 client.close(); 109 } 110 111 @Test getTriggerTest()112 public void getTriggerTest() throws Exception { 113 Trigger expectedResponse = 114 Trigger.newBuilder() 115 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 116 .setUid("uid115792") 117 .setCreateTime(Timestamp.newBuilder().build()) 118 .setUpdateTime(Timestamp.newBuilder().build()) 119 .addAllEventFilters(new ArrayList<EventFilter>()) 120 .setServiceAccount("serviceAccount1079137720") 121 .setDestination(Destination.newBuilder().build()) 122 .setTransport(Transport.newBuilder().build()) 123 .putAllLabels(new HashMap<String, String>()) 124 .setChannel("channel738950403") 125 .putAllConditions(new HashMap<String, StateCondition>()) 126 .setEtag("etag3123477") 127 .build(); 128 mockEventarc.addResponse(expectedResponse); 129 130 TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]"); 131 132 Trigger actualResponse = client.getTrigger(name); 133 Assert.assertEquals(expectedResponse, actualResponse); 134 135 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 136 Assert.assertEquals(1, actualRequests.size()); 137 GetTriggerRequest actualRequest = ((GetTriggerRequest) actualRequests.get(0)); 138 139 Assert.assertEquals(name.toString(), actualRequest.getName()); 140 Assert.assertTrue( 141 channelProvider.isHeaderSent( 142 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 143 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 144 } 145 146 @Test getTriggerExceptionTest()147 public void getTriggerExceptionTest() throws Exception { 148 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 149 mockEventarc.addException(exception); 150 151 try { 152 TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]"); 153 client.getTrigger(name); 154 Assert.fail("No exception raised"); 155 } catch (InvalidArgumentException e) { 156 // Expected exception. 157 } 158 } 159 160 @Test getTriggerTest2()161 public void getTriggerTest2() throws Exception { 162 Trigger expectedResponse = 163 Trigger.newBuilder() 164 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 165 .setUid("uid115792") 166 .setCreateTime(Timestamp.newBuilder().build()) 167 .setUpdateTime(Timestamp.newBuilder().build()) 168 .addAllEventFilters(new ArrayList<EventFilter>()) 169 .setServiceAccount("serviceAccount1079137720") 170 .setDestination(Destination.newBuilder().build()) 171 .setTransport(Transport.newBuilder().build()) 172 .putAllLabels(new HashMap<String, String>()) 173 .setChannel("channel738950403") 174 .putAllConditions(new HashMap<String, StateCondition>()) 175 .setEtag("etag3123477") 176 .build(); 177 mockEventarc.addResponse(expectedResponse); 178 179 String name = "name3373707"; 180 181 Trigger actualResponse = client.getTrigger(name); 182 Assert.assertEquals(expectedResponse, actualResponse); 183 184 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 185 Assert.assertEquals(1, actualRequests.size()); 186 GetTriggerRequest actualRequest = ((GetTriggerRequest) actualRequests.get(0)); 187 188 Assert.assertEquals(name, actualRequest.getName()); 189 Assert.assertTrue( 190 channelProvider.isHeaderSent( 191 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 192 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 193 } 194 195 @Test getTriggerExceptionTest2()196 public void getTriggerExceptionTest2() throws Exception { 197 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 198 mockEventarc.addException(exception); 199 200 try { 201 String name = "name3373707"; 202 client.getTrigger(name); 203 Assert.fail("No exception raised"); 204 } catch (InvalidArgumentException e) { 205 // Expected exception. 206 } 207 } 208 209 @Test listTriggersTest()210 public void listTriggersTest() throws Exception { 211 Trigger responsesElement = Trigger.newBuilder().build(); 212 ListTriggersResponse expectedResponse = 213 ListTriggersResponse.newBuilder() 214 .setNextPageToken("") 215 .addAllTriggers(Arrays.asList(responsesElement)) 216 .build(); 217 mockEventarc.addResponse(expectedResponse); 218 219 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 220 221 ListTriggersPagedResponse pagedListResponse = client.listTriggers(parent); 222 223 List<Trigger> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 224 225 Assert.assertEquals(1, resources.size()); 226 Assert.assertEquals(expectedResponse.getTriggersList().get(0), resources.get(0)); 227 228 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 229 Assert.assertEquals(1, actualRequests.size()); 230 ListTriggersRequest actualRequest = ((ListTriggersRequest) actualRequests.get(0)); 231 232 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 233 Assert.assertTrue( 234 channelProvider.isHeaderSent( 235 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 236 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 237 } 238 239 @Test listTriggersExceptionTest()240 public void listTriggersExceptionTest() throws Exception { 241 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 242 mockEventarc.addException(exception); 243 244 try { 245 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 246 client.listTriggers(parent); 247 Assert.fail("No exception raised"); 248 } catch (InvalidArgumentException e) { 249 // Expected exception. 250 } 251 } 252 253 @Test listTriggersTest2()254 public void listTriggersTest2() throws Exception { 255 Trigger responsesElement = Trigger.newBuilder().build(); 256 ListTriggersResponse expectedResponse = 257 ListTriggersResponse.newBuilder() 258 .setNextPageToken("") 259 .addAllTriggers(Arrays.asList(responsesElement)) 260 .build(); 261 mockEventarc.addResponse(expectedResponse); 262 263 String parent = "parent-995424086"; 264 265 ListTriggersPagedResponse pagedListResponse = client.listTriggers(parent); 266 267 List<Trigger> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 268 269 Assert.assertEquals(1, resources.size()); 270 Assert.assertEquals(expectedResponse.getTriggersList().get(0), resources.get(0)); 271 272 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 273 Assert.assertEquals(1, actualRequests.size()); 274 ListTriggersRequest actualRequest = ((ListTriggersRequest) actualRequests.get(0)); 275 276 Assert.assertEquals(parent, actualRequest.getParent()); 277 Assert.assertTrue( 278 channelProvider.isHeaderSent( 279 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 280 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 281 } 282 283 @Test listTriggersExceptionTest2()284 public void listTriggersExceptionTest2() throws Exception { 285 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 286 mockEventarc.addException(exception); 287 288 try { 289 String parent = "parent-995424086"; 290 client.listTriggers(parent); 291 Assert.fail("No exception raised"); 292 } catch (InvalidArgumentException e) { 293 // Expected exception. 294 } 295 } 296 297 @Test createTriggerTest()298 public void createTriggerTest() throws Exception { 299 Trigger expectedResponse = 300 Trigger.newBuilder() 301 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 302 .setUid("uid115792") 303 .setCreateTime(Timestamp.newBuilder().build()) 304 .setUpdateTime(Timestamp.newBuilder().build()) 305 .addAllEventFilters(new ArrayList<EventFilter>()) 306 .setServiceAccount("serviceAccount1079137720") 307 .setDestination(Destination.newBuilder().build()) 308 .setTransport(Transport.newBuilder().build()) 309 .putAllLabels(new HashMap<String, String>()) 310 .setChannel("channel738950403") 311 .putAllConditions(new HashMap<String, StateCondition>()) 312 .setEtag("etag3123477") 313 .build(); 314 Operation resultOperation = 315 Operation.newBuilder() 316 .setName("createTriggerTest") 317 .setDone(true) 318 .setResponse(Any.pack(expectedResponse)) 319 .build(); 320 mockEventarc.addResponse(resultOperation); 321 322 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 323 Trigger trigger = Trigger.newBuilder().build(); 324 String triggerId = "triggerId-648752909"; 325 326 Trigger actualResponse = client.createTriggerAsync(parent, trigger, triggerId).get(); 327 Assert.assertEquals(expectedResponse, actualResponse); 328 329 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 330 Assert.assertEquals(1, actualRequests.size()); 331 CreateTriggerRequest actualRequest = ((CreateTriggerRequest) actualRequests.get(0)); 332 333 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 334 Assert.assertEquals(trigger, actualRequest.getTrigger()); 335 Assert.assertEquals(triggerId, actualRequest.getTriggerId()); 336 Assert.assertTrue( 337 channelProvider.isHeaderSent( 338 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 339 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 340 } 341 342 @Test createTriggerExceptionTest()343 public void createTriggerExceptionTest() throws Exception { 344 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 345 mockEventarc.addException(exception); 346 347 try { 348 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 349 Trigger trigger = Trigger.newBuilder().build(); 350 String triggerId = "triggerId-648752909"; 351 client.createTriggerAsync(parent, trigger, triggerId).get(); 352 Assert.fail("No exception raised"); 353 } catch (ExecutionException e) { 354 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 355 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 356 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 357 } 358 } 359 360 @Test createTriggerTest2()361 public void createTriggerTest2() throws Exception { 362 Trigger expectedResponse = 363 Trigger.newBuilder() 364 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 365 .setUid("uid115792") 366 .setCreateTime(Timestamp.newBuilder().build()) 367 .setUpdateTime(Timestamp.newBuilder().build()) 368 .addAllEventFilters(new ArrayList<EventFilter>()) 369 .setServiceAccount("serviceAccount1079137720") 370 .setDestination(Destination.newBuilder().build()) 371 .setTransport(Transport.newBuilder().build()) 372 .putAllLabels(new HashMap<String, String>()) 373 .setChannel("channel738950403") 374 .putAllConditions(new HashMap<String, StateCondition>()) 375 .setEtag("etag3123477") 376 .build(); 377 Operation resultOperation = 378 Operation.newBuilder() 379 .setName("createTriggerTest") 380 .setDone(true) 381 .setResponse(Any.pack(expectedResponse)) 382 .build(); 383 mockEventarc.addResponse(resultOperation); 384 385 String parent = "parent-995424086"; 386 Trigger trigger = Trigger.newBuilder().build(); 387 String triggerId = "triggerId-648752909"; 388 389 Trigger actualResponse = client.createTriggerAsync(parent, trigger, triggerId).get(); 390 Assert.assertEquals(expectedResponse, actualResponse); 391 392 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 393 Assert.assertEquals(1, actualRequests.size()); 394 CreateTriggerRequest actualRequest = ((CreateTriggerRequest) actualRequests.get(0)); 395 396 Assert.assertEquals(parent, actualRequest.getParent()); 397 Assert.assertEquals(trigger, actualRequest.getTrigger()); 398 Assert.assertEquals(triggerId, actualRequest.getTriggerId()); 399 Assert.assertTrue( 400 channelProvider.isHeaderSent( 401 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 402 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 403 } 404 405 @Test createTriggerExceptionTest2()406 public void createTriggerExceptionTest2() throws Exception { 407 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 408 mockEventarc.addException(exception); 409 410 try { 411 String parent = "parent-995424086"; 412 Trigger trigger = Trigger.newBuilder().build(); 413 String triggerId = "triggerId-648752909"; 414 client.createTriggerAsync(parent, trigger, triggerId).get(); 415 Assert.fail("No exception raised"); 416 } catch (ExecutionException e) { 417 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 418 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 419 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 420 } 421 } 422 423 @Test updateTriggerTest()424 public void updateTriggerTest() throws Exception { 425 Trigger expectedResponse = 426 Trigger.newBuilder() 427 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 428 .setUid("uid115792") 429 .setCreateTime(Timestamp.newBuilder().build()) 430 .setUpdateTime(Timestamp.newBuilder().build()) 431 .addAllEventFilters(new ArrayList<EventFilter>()) 432 .setServiceAccount("serviceAccount1079137720") 433 .setDestination(Destination.newBuilder().build()) 434 .setTransport(Transport.newBuilder().build()) 435 .putAllLabels(new HashMap<String, String>()) 436 .setChannel("channel738950403") 437 .putAllConditions(new HashMap<String, StateCondition>()) 438 .setEtag("etag3123477") 439 .build(); 440 Operation resultOperation = 441 Operation.newBuilder() 442 .setName("updateTriggerTest") 443 .setDone(true) 444 .setResponse(Any.pack(expectedResponse)) 445 .build(); 446 mockEventarc.addResponse(resultOperation); 447 448 Trigger trigger = Trigger.newBuilder().build(); 449 FieldMask updateMask = FieldMask.newBuilder().build(); 450 boolean allowMissing = true; 451 452 Trigger actualResponse = client.updateTriggerAsync(trigger, updateMask, allowMissing).get(); 453 Assert.assertEquals(expectedResponse, actualResponse); 454 455 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 456 Assert.assertEquals(1, actualRequests.size()); 457 UpdateTriggerRequest actualRequest = ((UpdateTriggerRequest) actualRequests.get(0)); 458 459 Assert.assertEquals(trigger, actualRequest.getTrigger()); 460 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 461 Assert.assertEquals(allowMissing, actualRequest.getAllowMissing()); 462 Assert.assertTrue( 463 channelProvider.isHeaderSent( 464 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 465 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 466 } 467 468 @Test updateTriggerExceptionTest()469 public void updateTriggerExceptionTest() throws Exception { 470 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 471 mockEventarc.addException(exception); 472 473 try { 474 Trigger trigger = Trigger.newBuilder().build(); 475 FieldMask updateMask = FieldMask.newBuilder().build(); 476 boolean allowMissing = true; 477 client.updateTriggerAsync(trigger, updateMask, allowMissing).get(); 478 Assert.fail("No exception raised"); 479 } catch (ExecutionException e) { 480 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 481 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 482 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 483 } 484 } 485 486 @Test deleteTriggerTest()487 public void deleteTriggerTest() throws Exception { 488 Trigger expectedResponse = 489 Trigger.newBuilder() 490 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 491 .setUid("uid115792") 492 .setCreateTime(Timestamp.newBuilder().build()) 493 .setUpdateTime(Timestamp.newBuilder().build()) 494 .addAllEventFilters(new ArrayList<EventFilter>()) 495 .setServiceAccount("serviceAccount1079137720") 496 .setDestination(Destination.newBuilder().build()) 497 .setTransport(Transport.newBuilder().build()) 498 .putAllLabels(new HashMap<String, String>()) 499 .setChannel("channel738950403") 500 .putAllConditions(new HashMap<String, StateCondition>()) 501 .setEtag("etag3123477") 502 .build(); 503 Operation resultOperation = 504 Operation.newBuilder() 505 .setName("deleteTriggerTest") 506 .setDone(true) 507 .setResponse(Any.pack(expectedResponse)) 508 .build(); 509 mockEventarc.addResponse(resultOperation); 510 511 TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]"); 512 boolean allowMissing = true; 513 514 Trigger actualResponse = client.deleteTriggerAsync(name, allowMissing).get(); 515 Assert.assertEquals(expectedResponse, actualResponse); 516 517 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 518 Assert.assertEquals(1, actualRequests.size()); 519 DeleteTriggerRequest actualRequest = ((DeleteTriggerRequest) actualRequests.get(0)); 520 521 Assert.assertEquals(name.toString(), actualRequest.getName()); 522 Assert.assertEquals(allowMissing, actualRequest.getAllowMissing()); 523 Assert.assertTrue( 524 channelProvider.isHeaderSent( 525 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 526 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 527 } 528 529 @Test deleteTriggerExceptionTest()530 public void deleteTriggerExceptionTest() throws Exception { 531 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 532 mockEventarc.addException(exception); 533 534 try { 535 TriggerName name = TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]"); 536 boolean allowMissing = true; 537 client.deleteTriggerAsync(name, allowMissing).get(); 538 Assert.fail("No exception raised"); 539 } catch (ExecutionException e) { 540 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 541 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 542 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 543 } 544 } 545 546 @Test deleteTriggerTest2()547 public void deleteTriggerTest2() throws Exception { 548 Trigger expectedResponse = 549 Trigger.newBuilder() 550 .setName(TriggerName.of("[PROJECT]", "[LOCATION]", "[TRIGGER]").toString()) 551 .setUid("uid115792") 552 .setCreateTime(Timestamp.newBuilder().build()) 553 .setUpdateTime(Timestamp.newBuilder().build()) 554 .addAllEventFilters(new ArrayList<EventFilter>()) 555 .setServiceAccount("serviceAccount1079137720") 556 .setDestination(Destination.newBuilder().build()) 557 .setTransport(Transport.newBuilder().build()) 558 .putAllLabels(new HashMap<String, String>()) 559 .setChannel("channel738950403") 560 .putAllConditions(new HashMap<String, StateCondition>()) 561 .setEtag("etag3123477") 562 .build(); 563 Operation resultOperation = 564 Operation.newBuilder() 565 .setName("deleteTriggerTest") 566 .setDone(true) 567 .setResponse(Any.pack(expectedResponse)) 568 .build(); 569 mockEventarc.addResponse(resultOperation); 570 571 String name = "name3373707"; 572 boolean allowMissing = true; 573 574 Trigger actualResponse = client.deleteTriggerAsync(name, allowMissing).get(); 575 Assert.assertEquals(expectedResponse, actualResponse); 576 577 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 578 Assert.assertEquals(1, actualRequests.size()); 579 DeleteTriggerRequest actualRequest = ((DeleteTriggerRequest) actualRequests.get(0)); 580 581 Assert.assertEquals(name, actualRequest.getName()); 582 Assert.assertEquals(allowMissing, actualRequest.getAllowMissing()); 583 Assert.assertTrue( 584 channelProvider.isHeaderSent( 585 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 586 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 587 } 588 589 @Test deleteTriggerExceptionTest2()590 public void deleteTriggerExceptionTest2() throws Exception { 591 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 592 mockEventarc.addException(exception); 593 594 try { 595 String name = "name3373707"; 596 boolean allowMissing = true; 597 client.deleteTriggerAsync(name, allowMissing).get(); 598 Assert.fail("No exception raised"); 599 } catch (ExecutionException e) { 600 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 601 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 602 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 603 } 604 } 605 606 @Test getChannelTest()607 public void getChannelTest() throws Exception { 608 Channel expectedResponse = 609 Channel.newBuilder() 610 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 611 .setUid("uid115792") 612 .setCreateTime(Timestamp.newBuilder().build()) 613 .setUpdateTime(Timestamp.newBuilder().build()) 614 .setProvider("provider-987494927") 615 .setActivationToken("activationToken1276937859") 616 .setCryptoKeyName("cryptoKeyName1447084425") 617 .build(); 618 mockEventarc.addResponse(expectedResponse); 619 620 ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]"); 621 622 Channel actualResponse = client.getChannel(name); 623 Assert.assertEquals(expectedResponse, actualResponse); 624 625 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 626 Assert.assertEquals(1, actualRequests.size()); 627 GetChannelRequest actualRequest = ((GetChannelRequest) actualRequests.get(0)); 628 629 Assert.assertEquals(name.toString(), actualRequest.getName()); 630 Assert.assertTrue( 631 channelProvider.isHeaderSent( 632 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 633 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 634 } 635 636 @Test getChannelExceptionTest()637 public void getChannelExceptionTest() throws Exception { 638 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 639 mockEventarc.addException(exception); 640 641 try { 642 ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]"); 643 client.getChannel(name); 644 Assert.fail("No exception raised"); 645 } catch (InvalidArgumentException e) { 646 // Expected exception. 647 } 648 } 649 650 @Test getChannelTest2()651 public void getChannelTest2() throws Exception { 652 Channel expectedResponse = 653 Channel.newBuilder() 654 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 655 .setUid("uid115792") 656 .setCreateTime(Timestamp.newBuilder().build()) 657 .setUpdateTime(Timestamp.newBuilder().build()) 658 .setProvider("provider-987494927") 659 .setActivationToken("activationToken1276937859") 660 .setCryptoKeyName("cryptoKeyName1447084425") 661 .build(); 662 mockEventarc.addResponse(expectedResponse); 663 664 String name = "name3373707"; 665 666 Channel actualResponse = client.getChannel(name); 667 Assert.assertEquals(expectedResponse, actualResponse); 668 669 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 670 Assert.assertEquals(1, actualRequests.size()); 671 GetChannelRequest actualRequest = ((GetChannelRequest) actualRequests.get(0)); 672 673 Assert.assertEquals(name, actualRequest.getName()); 674 Assert.assertTrue( 675 channelProvider.isHeaderSent( 676 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 677 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 678 } 679 680 @Test getChannelExceptionTest2()681 public void getChannelExceptionTest2() throws Exception { 682 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 683 mockEventarc.addException(exception); 684 685 try { 686 String name = "name3373707"; 687 client.getChannel(name); 688 Assert.fail("No exception raised"); 689 } catch (InvalidArgumentException e) { 690 // Expected exception. 691 } 692 } 693 694 @Test listChannelsTest()695 public void listChannelsTest() throws Exception { 696 Channel responsesElement = Channel.newBuilder().build(); 697 ListChannelsResponse expectedResponse = 698 ListChannelsResponse.newBuilder() 699 .setNextPageToken("") 700 .addAllChannels(Arrays.asList(responsesElement)) 701 .build(); 702 mockEventarc.addResponse(expectedResponse); 703 704 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 705 706 ListChannelsPagedResponse pagedListResponse = client.listChannels(parent); 707 708 List<Channel> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 709 710 Assert.assertEquals(1, resources.size()); 711 Assert.assertEquals(expectedResponse.getChannelsList().get(0), resources.get(0)); 712 713 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 714 Assert.assertEquals(1, actualRequests.size()); 715 ListChannelsRequest actualRequest = ((ListChannelsRequest) actualRequests.get(0)); 716 717 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 718 Assert.assertTrue( 719 channelProvider.isHeaderSent( 720 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 721 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 722 } 723 724 @Test listChannelsExceptionTest()725 public void listChannelsExceptionTest() throws Exception { 726 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 727 mockEventarc.addException(exception); 728 729 try { 730 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 731 client.listChannels(parent); 732 Assert.fail("No exception raised"); 733 } catch (InvalidArgumentException e) { 734 // Expected exception. 735 } 736 } 737 738 @Test listChannelsTest2()739 public void listChannelsTest2() throws Exception { 740 Channel responsesElement = Channel.newBuilder().build(); 741 ListChannelsResponse expectedResponse = 742 ListChannelsResponse.newBuilder() 743 .setNextPageToken("") 744 .addAllChannels(Arrays.asList(responsesElement)) 745 .build(); 746 mockEventarc.addResponse(expectedResponse); 747 748 String parent = "parent-995424086"; 749 750 ListChannelsPagedResponse pagedListResponse = client.listChannels(parent); 751 752 List<Channel> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 753 754 Assert.assertEquals(1, resources.size()); 755 Assert.assertEquals(expectedResponse.getChannelsList().get(0), resources.get(0)); 756 757 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 758 Assert.assertEquals(1, actualRequests.size()); 759 ListChannelsRequest actualRequest = ((ListChannelsRequest) actualRequests.get(0)); 760 761 Assert.assertEquals(parent, actualRequest.getParent()); 762 Assert.assertTrue( 763 channelProvider.isHeaderSent( 764 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 765 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 766 } 767 768 @Test listChannelsExceptionTest2()769 public void listChannelsExceptionTest2() throws Exception { 770 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 771 mockEventarc.addException(exception); 772 773 try { 774 String parent = "parent-995424086"; 775 client.listChannels(parent); 776 Assert.fail("No exception raised"); 777 } catch (InvalidArgumentException e) { 778 // Expected exception. 779 } 780 } 781 782 @Test createChannelTest()783 public void createChannelTest() throws Exception { 784 Channel expectedResponse = 785 Channel.newBuilder() 786 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 787 .setUid("uid115792") 788 .setCreateTime(Timestamp.newBuilder().build()) 789 .setUpdateTime(Timestamp.newBuilder().build()) 790 .setProvider("provider-987494927") 791 .setActivationToken("activationToken1276937859") 792 .setCryptoKeyName("cryptoKeyName1447084425") 793 .build(); 794 Operation resultOperation = 795 Operation.newBuilder() 796 .setName("createChannelTest") 797 .setDone(true) 798 .setResponse(Any.pack(expectedResponse)) 799 .build(); 800 mockEventarc.addResponse(resultOperation); 801 802 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 803 Channel channel = Channel.newBuilder().build(); 804 String channelId = "channelId1461735806"; 805 806 Channel actualResponse = client.createChannelAsync(parent, channel, channelId).get(); 807 Assert.assertEquals(expectedResponse, actualResponse); 808 809 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 810 Assert.assertEquals(1, actualRequests.size()); 811 CreateChannelRequest actualRequest = ((CreateChannelRequest) actualRequests.get(0)); 812 813 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 814 Assert.assertEquals(channel, actualRequest.getChannel()); 815 Assert.assertEquals(channelId, actualRequest.getChannelId()); 816 Assert.assertTrue( 817 channelProvider.isHeaderSent( 818 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 819 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 820 } 821 822 @Test createChannelExceptionTest()823 public void createChannelExceptionTest() throws Exception { 824 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 825 mockEventarc.addException(exception); 826 827 try { 828 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 829 Channel channel = Channel.newBuilder().build(); 830 String channelId = "channelId1461735806"; 831 client.createChannelAsync(parent, channel, channelId).get(); 832 Assert.fail("No exception raised"); 833 } catch (ExecutionException e) { 834 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 835 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 836 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 837 } 838 } 839 840 @Test createChannelTest2()841 public void createChannelTest2() throws Exception { 842 Channel expectedResponse = 843 Channel.newBuilder() 844 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 845 .setUid("uid115792") 846 .setCreateTime(Timestamp.newBuilder().build()) 847 .setUpdateTime(Timestamp.newBuilder().build()) 848 .setProvider("provider-987494927") 849 .setActivationToken("activationToken1276937859") 850 .setCryptoKeyName("cryptoKeyName1447084425") 851 .build(); 852 Operation resultOperation = 853 Operation.newBuilder() 854 .setName("createChannelTest") 855 .setDone(true) 856 .setResponse(Any.pack(expectedResponse)) 857 .build(); 858 mockEventarc.addResponse(resultOperation); 859 860 String parent = "parent-995424086"; 861 Channel channel = Channel.newBuilder().build(); 862 String channelId = "channelId1461735806"; 863 864 Channel actualResponse = client.createChannelAsync(parent, channel, channelId).get(); 865 Assert.assertEquals(expectedResponse, actualResponse); 866 867 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 868 Assert.assertEquals(1, actualRequests.size()); 869 CreateChannelRequest actualRequest = ((CreateChannelRequest) actualRequests.get(0)); 870 871 Assert.assertEquals(parent, actualRequest.getParent()); 872 Assert.assertEquals(channel, actualRequest.getChannel()); 873 Assert.assertEquals(channelId, actualRequest.getChannelId()); 874 Assert.assertTrue( 875 channelProvider.isHeaderSent( 876 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 877 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 878 } 879 880 @Test createChannelExceptionTest2()881 public void createChannelExceptionTest2() throws Exception { 882 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 883 mockEventarc.addException(exception); 884 885 try { 886 String parent = "parent-995424086"; 887 Channel channel = Channel.newBuilder().build(); 888 String channelId = "channelId1461735806"; 889 client.createChannelAsync(parent, channel, channelId).get(); 890 Assert.fail("No exception raised"); 891 } catch (ExecutionException e) { 892 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 893 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 894 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 895 } 896 } 897 898 @Test updateChannelTest()899 public void updateChannelTest() throws Exception { 900 Channel expectedResponse = 901 Channel.newBuilder() 902 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 903 .setUid("uid115792") 904 .setCreateTime(Timestamp.newBuilder().build()) 905 .setUpdateTime(Timestamp.newBuilder().build()) 906 .setProvider("provider-987494927") 907 .setActivationToken("activationToken1276937859") 908 .setCryptoKeyName("cryptoKeyName1447084425") 909 .build(); 910 Operation resultOperation = 911 Operation.newBuilder() 912 .setName("updateChannelTest") 913 .setDone(true) 914 .setResponse(Any.pack(expectedResponse)) 915 .build(); 916 mockEventarc.addResponse(resultOperation); 917 918 Channel channel = Channel.newBuilder().build(); 919 FieldMask updateMask = FieldMask.newBuilder().build(); 920 921 Channel actualResponse = client.updateChannelAsync(channel, updateMask).get(); 922 Assert.assertEquals(expectedResponse, actualResponse); 923 924 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 925 Assert.assertEquals(1, actualRequests.size()); 926 UpdateChannelRequest actualRequest = ((UpdateChannelRequest) actualRequests.get(0)); 927 928 Assert.assertEquals(channel, actualRequest.getChannel()); 929 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 930 Assert.assertTrue( 931 channelProvider.isHeaderSent( 932 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 933 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 934 } 935 936 @Test updateChannelExceptionTest()937 public void updateChannelExceptionTest() throws Exception { 938 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 939 mockEventarc.addException(exception); 940 941 try { 942 Channel channel = Channel.newBuilder().build(); 943 FieldMask updateMask = FieldMask.newBuilder().build(); 944 client.updateChannelAsync(channel, updateMask).get(); 945 Assert.fail("No exception raised"); 946 } catch (ExecutionException e) { 947 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 948 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 949 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 950 } 951 } 952 953 @Test deleteChannelTest()954 public void deleteChannelTest() throws Exception { 955 Channel expectedResponse = 956 Channel.newBuilder() 957 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 958 .setUid("uid115792") 959 .setCreateTime(Timestamp.newBuilder().build()) 960 .setUpdateTime(Timestamp.newBuilder().build()) 961 .setProvider("provider-987494927") 962 .setActivationToken("activationToken1276937859") 963 .setCryptoKeyName("cryptoKeyName1447084425") 964 .build(); 965 Operation resultOperation = 966 Operation.newBuilder() 967 .setName("deleteChannelTest") 968 .setDone(true) 969 .setResponse(Any.pack(expectedResponse)) 970 .build(); 971 mockEventarc.addResponse(resultOperation); 972 973 ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]"); 974 975 Channel actualResponse = client.deleteChannelAsync(name).get(); 976 Assert.assertEquals(expectedResponse, actualResponse); 977 978 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 979 Assert.assertEquals(1, actualRequests.size()); 980 DeleteChannelRequest actualRequest = ((DeleteChannelRequest) actualRequests.get(0)); 981 982 Assert.assertEquals(name.toString(), actualRequest.getName()); 983 Assert.assertTrue( 984 channelProvider.isHeaderSent( 985 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 986 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 987 } 988 989 @Test deleteChannelExceptionTest()990 public void deleteChannelExceptionTest() throws Exception { 991 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 992 mockEventarc.addException(exception); 993 994 try { 995 ChannelName name = ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]"); 996 client.deleteChannelAsync(name).get(); 997 Assert.fail("No exception raised"); 998 } catch (ExecutionException e) { 999 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1000 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1001 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1002 } 1003 } 1004 1005 @Test deleteChannelTest2()1006 public void deleteChannelTest2() throws Exception { 1007 Channel expectedResponse = 1008 Channel.newBuilder() 1009 .setName(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1010 .setUid("uid115792") 1011 .setCreateTime(Timestamp.newBuilder().build()) 1012 .setUpdateTime(Timestamp.newBuilder().build()) 1013 .setProvider("provider-987494927") 1014 .setActivationToken("activationToken1276937859") 1015 .setCryptoKeyName("cryptoKeyName1447084425") 1016 .build(); 1017 Operation resultOperation = 1018 Operation.newBuilder() 1019 .setName("deleteChannelTest") 1020 .setDone(true) 1021 .setResponse(Any.pack(expectedResponse)) 1022 .build(); 1023 mockEventarc.addResponse(resultOperation); 1024 1025 String name = "name3373707"; 1026 1027 Channel actualResponse = client.deleteChannelAsync(name).get(); 1028 Assert.assertEquals(expectedResponse, actualResponse); 1029 1030 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1031 Assert.assertEquals(1, actualRequests.size()); 1032 DeleteChannelRequest actualRequest = ((DeleteChannelRequest) actualRequests.get(0)); 1033 1034 Assert.assertEquals(name, actualRequest.getName()); 1035 Assert.assertTrue( 1036 channelProvider.isHeaderSent( 1037 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1038 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1039 } 1040 1041 @Test deleteChannelExceptionTest2()1042 public void deleteChannelExceptionTest2() throws Exception { 1043 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1044 mockEventarc.addException(exception); 1045 1046 try { 1047 String name = "name3373707"; 1048 client.deleteChannelAsync(name).get(); 1049 Assert.fail("No exception raised"); 1050 } catch (ExecutionException e) { 1051 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1052 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1053 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1054 } 1055 } 1056 1057 @Test getProviderTest()1058 public void getProviderTest() throws Exception { 1059 Provider expectedResponse = 1060 Provider.newBuilder() 1061 .setName(ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]").toString()) 1062 .setDisplayName("displayName1714148973") 1063 .addAllEventTypes(new ArrayList<EventType>()) 1064 .build(); 1065 mockEventarc.addResponse(expectedResponse); 1066 1067 ProviderName name = ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]"); 1068 1069 Provider actualResponse = client.getProvider(name); 1070 Assert.assertEquals(expectedResponse, actualResponse); 1071 1072 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1073 Assert.assertEquals(1, actualRequests.size()); 1074 GetProviderRequest actualRequest = ((GetProviderRequest) actualRequests.get(0)); 1075 1076 Assert.assertEquals(name.toString(), actualRequest.getName()); 1077 Assert.assertTrue( 1078 channelProvider.isHeaderSent( 1079 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1080 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1081 } 1082 1083 @Test getProviderExceptionTest()1084 public void getProviderExceptionTest() throws Exception { 1085 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1086 mockEventarc.addException(exception); 1087 1088 try { 1089 ProviderName name = ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]"); 1090 client.getProvider(name); 1091 Assert.fail("No exception raised"); 1092 } catch (InvalidArgumentException e) { 1093 // Expected exception. 1094 } 1095 } 1096 1097 @Test getProviderTest2()1098 public void getProviderTest2() throws Exception { 1099 Provider expectedResponse = 1100 Provider.newBuilder() 1101 .setName(ProviderName.of("[PROJECT]", "[LOCATION]", "[PROVIDER]").toString()) 1102 .setDisplayName("displayName1714148973") 1103 .addAllEventTypes(new ArrayList<EventType>()) 1104 .build(); 1105 mockEventarc.addResponse(expectedResponse); 1106 1107 String name = "name3373707"; 1108 1109 Provider actualResponse = client.getProvider(name); 1110 Assert.assertEquals(expectedResponse, actualResponse); 1111 1112 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1113 Assert.assertEquals(1, actualRequests.size()); 1114 GetProviderRequest actualRequest = ((GetProviderRequest) actualRequests.get(0)); 1115 1116 Assert.assertEquals(name, actualRequest.getName()); 1117 Assert.assertTrue( 1118 channelProvider.isHeaderSent( 1119 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1120 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1121 } 1122 1123 @Test getProviderExceptionTest2()1124 public void getProviderExceptionTest2() throws Exception { 1125 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1126 mockEventarc.addException(exception); 1127 1128 try { 1129 String name = "name3373707"; 1130 client.getProvider(name); 1131 Assert.fail("No exception raised"); 1132 } catch (InvalidArgumentException e) { 1133 // Expected exception. 1134 } 1135 } 1136 1137 @Test listProvidersTest()1138 public void listProvidersTest() throws Exception { 1139 Provider responsesElement = Provider.newBuilder().build(); 1140 ListProvidersResponse expectedResponse = 1141 ListProvidersResponse.newBuilder() 1142 .setNextPageToken("") 1143 .addAllProviders(Arrays.asList(responsesElement)) 1144 .build(); 1145 mockEventarc.addResponse(expectedResponse); 1146 1147 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 1148 1149 ListProvidersPagedResponse pagedListResponse = client.listProviders(parent); 1150 1151 List<Provider> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1152 1153 Assert.assertEquals(1, resources.size()); 1154 Assert.assertEquals(expectedResponse.getProvidersList().get(0), resources.get(0)); 1155 1156 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1157 Assert.assertEquals(1, actualRequests.size()); 1158 ListProvidersRequest actualRequest = ((ListProvidersRequest) actualRequests.get(0)); 1159 1160 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1161 Assert.assertTrue( 1162 channelProvider.isHeaderSent( 1163 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1164 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1165 } 1166 1167 @Test listProvidersExceptionTest()1168 public void listProvidersExceptionTest() throws Exception { 1169 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1170 mockEventarc.addException(exception); 1171 1172 try { 1173 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 1174 client.listProviders(parent); 1175 Assert.fail("No exception raised"); 1176 } catch (InvalidArgumentException e) { 1177 // Expected exception. 1178 } 1179 } 1180 1181 @Test listProvidersTest2()1182 public void listProvidersTest2() throws Exception { 1183 Provider responsesElement = Provider.newBuilder().build(); 1184 ListProvidersResponse expectedResponse = 1185 ListProvidersResponse.newBuilder() 1186 .setNextPageToken("") 1187 .addAllProviders(Arrays.asList(responsesElement)) 1188 .build(); 1189 mockEventarc.addResponse(expectedResponse); 1190 1191 String parent = "parent-995424086"; 1192 1193 ListProvidersPagedResponse pagedListResponse = client.listProviders(parent); 1194 1195 List<Provider> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1196 1197 Assert.assertEquals(1, resources.size()); 1198 Assert.assertEquals(expectedResponse.getProvidersList().get(0), resources.get(0)); 1199 1200 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1201 Assert.assertEquals(1, actualRequests.size()); 1202 ListProvidersRequest actualRequest = ((ListProvidersRequest) actualRequests.get(0)); 1203 1204 Assert.assertEquals(parent, actualRequest.getParent()); 1205 Assert.assertTrue( 1206 channelProvider.isHeaderSent( 1207 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1208 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1209 } 1210 1211 @Test listProvidersExceptionTest2()1212 public void listProvidersExceptionTest2() throws Exception { 1213 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1214 mockEventarc.addException(exception); 1215 1216 try { 1217 String parent = "parent-995424086"; 1218 client.listProviders(parent); 1219 Assert.fail("No exception raised"); 1220 } catch (InvalidArgumentException e) { 1221 // Expected exception. 1222 } 1223 } 1224 1225 @Test getChannelConnectionTest()1226 public void getChannelConnectionTest() throws Exception { 1227 ChannelConnection expectedResponse = 1228 ChannelConnection.newBuilder() 1229 .setName( 1230 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]") 1231 .toString()) 1232 .setUid("uid115792") 1233 .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1234 .setCreateTime(Timestamp.newBuilder().build()) 1235 .setUpdateTime(Timestamp.newBuilder().build()) 1236 .setActivationToken("activationToken1276937859") 1237 .build(); 1238 mockEventarc.addResponse(expectedResponse); 1239 1240 ChannelConnectionName name = 1241 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]"); 1242 1243 ChannelConnection actualResponse = client.getChannelConnection(name); 1244 Assert.assertEquals(expectedResponse, actualResponse); 1245 1246 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1247 Assert.assertEquals(1, actualRequests.size()); 1248 GetChannelConnectionRequest actualRequest = 1249 ((GetChannelConnectionRequest) actualRequests.get(0)); 1250 1251 Assert.assertEquals(name.toString(), actualRequest.getName()); 1252 Assert.assertTrue( 1253 channelProvider.isHeaderSent( 1254 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1255 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1256 } 1257 1258 @Test getChannelConnectionExceptionTest()1259 public void getChannelConnectionExceptionTest() throws Exception { 1260 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1261 mockEventarc.addException(exception); 1262 1263 try { 1264 ChannelConnectionName name = 1265 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]"); 1266 client.getChannelConnection(name); 1267 Assert.fail("No exception raised"); 1268 } catch (InvalidArgumentException e) { 1269 // Expected exception. 1270 } 1271 } 1272 1273 @Test getChannelConnectionTest2()1274 public void getChannelConnectionTest2() throws Exception { 1275 ChannelConnection expectedResponse = 1276 ChannelConnection.newBuilder() 1277 .setName( 1278 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]") 1279 .toString()) 1280 .setUid("uid115792") 1281 .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1282 .setCreateTime(Timestamp.newBuilder().build()) 1283 .setUpdateTime(Timestamp.newBuilder().build()) 1284 .setActivationToken("activationToken1276937859") 1285 .build(); 1286 mockEventarc.addResponse(expectedResponse); 1287 1288 String name = "name3373707"; 1289 1290 ChannelConnection actualResponse = client.getChannelConnection(name); 1291 Assert.assertEquals(expectedResponse, actualResponse); 1292 1293 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1294 Assert.assertEquals(1, actualRequests.size()); 1295 GetChannelConnectionRequest actualRequest = 1296 ((GetChannelConnectionRequest) actualRequests.get(0)); 1297 1298 Assert.assertEquals(name, actualRequest.getName()); 1299 Assert.assertTrue( 1300 channelProvider.isHeaderSent( 1301 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1302 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1303 } 1304 1305 @Test getChannelConnectionExceptionTest2()1306 public void getChannelConnectionExceptionTest2() throws Exception { 1307 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1308 mockEventarc.addException(exception); 1309 1310 try { 1311 String name = "name3373707"; 1312 client.getChannelConnection(name); 1313 Assert.fail("No exception raised"); 1314 } catch (InvalidArgumentException e) { 1315 // Expected exception. 1316 } 1317 } 1318 1319 @Test listChannelConnectionsTest()1320 public void listChannelConnectionsTest() throws Exception { 1321 ChannelConnection responsesElement = ChannelConnection.newBuilder().build(); 1322 ListChannelConnectionsResponse expectedResponse = 1323 ListChannelConnectionsResponse.newBuilder() 1324 .setNextPageToken("") 1325 .addAllChannelConnections(Arrays.asList(responsesElement)) 1326 .build(); 1327 mockEventarc.addResponse(expectedResponse); 1328 1329 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 1330 1331 ListChannelConnectionsPagedResponse pagedListResponse = client.listChannelConnections(parent); 1332 1333 List<ChannelConnection> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1334 1335 Assert.assertEquals(1, resources.size()); 1336 Assert.assertEquals(expectedResponse.getChannelConnectionsList().get(0), resources.get(0)); 1337 1338 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1339 Assert.assertEquals(1, actualRequests.size()); 1340 ListChannelConnectionsRequest actualRequest = 1341 ((ListChannelConnectionsRequest) actualRequests.get(0)); 1342 1343 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1344 Assert.assertTrue( 1345 channelProvider.isHeaderSent( 1346 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1347 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1348 } 1349 1350 @Test listChannelConnectionsExceptionTest()1351 public void listChannelConnectionsExceptionTest() throws Exception { 1352 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1353 mockEventarc.addException(exception); 1354 1355 try { 1356 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 1357 client.listChannelConnections(parent); 1358 Assert.fail("No exception raised"); 1359 } catch (InvalidArgumentException e) { 1360 // Expected exception. 1361 } 1362 } 1363 1364 @Test listChannelConnectionsTest2()1365 public void listChannelConnectionsTest2() throws Exception { 1366 ChannelConnection responsesElement = ChannelConnection.newBuilder().build(); 1367 ListChannelConnectionsResponse expectedResponse = 1368 ListChannelConnectionsResponse.newBuilder() 1369 .setNextPageToken("") 1370 .addAllChannelConnections(Arrays.asList(responsesElement)) 1371 .build(); 1372 mockEventarc.addResponse(expectedResponse); 1373 1374 String parent = "parent-995424086"; 1375 1376 ListChannelConnectionsPagedResponse pagedListResponse = client.listChannelConnections(parent); 1377 1378 List<ChannelConnection> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1379 1380 Assert.assertEquals(1, resources.size()); 1381 Assert.assertEquals(expectedResponse.getChannelConnectionsList().get(0), resources.get(0)); 1382 1383 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1384 Assert.assertEquals(1, actualRequests.size()); 1385 ListChannelConnectionsRequest actualRequest = 1386 ((ListChannelConnectionsRequest) actualRequests.get(0)); 1387 1388 Assert.assertEquals(parent, actualRequest.getParent()); 1389 Assert.assertTrue( 1390 channelProvider.isHeaderSent( 1391 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1392 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1393 } 1394 1395 @Test listChannelConnectionsExceptionTest2()1396 public void listChannelConnectionsExceptionTest2() throws Exception { 1397 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1398 mockEventarc.addException(exception); 1399 1400 try { 1401 String parent = "parent-995424086"; 1402 client.listChannelConnections(parent); 1403 Assert.fail("No exception raised"); 1404 } catch (InvalidArgumentException e) { 1405 // Expected exception. 1406 } 1407 } 1408 1409 @Test createChannelConnectionTest()1410 public void createChannelConnectionTest() throws Exception { 1411 ChannelConnection expectedResponse = 1412 ChannelConnection.newBuilder() 1413 .setName( 1414 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]") 1415 .toString()) 1416 .setUid("uid115792") 1417 .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1418 .setCreateTime(Timestamp.newBuilder().build()) 1419 .setUpdateTime(Timestamp.newBuilder().build()) 1420 .setActivationToken("activationToken1276937859") 1421 .build(); 1422 Operation resultOperation = 1423 Operation.newBuilder() 1424 .setName("createChannelConnectionTest") 1425 .setDone(true) 1426 .setResponse(Any.pack(expectedResponse)) 1427 .build(); 1428 mockEventarc.addResponse(resultOperation); 1429 1430 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 1431 ChannelConnection channelConnection = ChannelConnection.newBuilder().build(); 1432 String channelConnectionId = "channelConnectionId-1246974660"; 1433 1434 ChannelConnection actualResponse = 1435 client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get(); 1436 Assert.assertEquals(expectedResponse, actualResponse); 1437 1438 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1439 Assert.assertEquals(1, actualRequests.size()); 1440 CreateChannelConnectionRequest actualRequest = 1441 ((CreateChannelConnectionRequest) actualRequests.get(0)); 1442 1443 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1444 Assert.assertEquals(channelConnection, actualRequest.getChannelConnection()); 1445 Assert.assertEquals(channelConnectionId, actualRequest.getChannelConnectionId()); 1446 Assert.assertTrue( 1447 channelProvider.isHeaderSent( 1448 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1449 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1450 } 1451 1452 @Test createChannelConnectionExceptionTest()1453 public void createChannelConnectionExceptionTest() throws Exception { 1454 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1455 mockEventarc.addException(exception); 1456 1457 try { 1458 LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 1459 ChannelConnection channelConnection = ChannelConnection.newBuilder().build(); 1460 String channelConnectionId = "channelConnectionId-1246974660"; 1461 client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get(); 1462 Assert.fail("No exception raised"); 1463 } catch (ExecutionException e) { 1464 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1465 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1466 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1467 } 1468 } 1469 1470 @Test createChannelConnectionTest2()1471 public void createChannelConnectionTest2() throws Exception { 1472 ChannelConnection expectedResponse = 1473 ChannelConnection.newBuilder() 1474 .setName( 1475 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]") 1476 .toString()) 1477 .setUid("uid115792") 1478 .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1479 .setCreateTime(Timestamp.newBuilder().build()) 1480 .setUpdateTime(Timestamp.newBuilder().build()) 1481 .setActivationToken("activationToken1276937859") 1482 .build(); 1483 Operation resultOperation = 1484 Operation.newBuilder() 1485 .setName("createChannelConnectionTest") 1486 .setDone(true) 1487 .setResponse(Any.pack(expectedResponse)) 1488 .build(); 1489 mockEventarc.addResponse(resultOperation); 1490 1491 String parent = "parent-995424086"; 1492 ChannelConnection channelConnection = ChannelConnection.newBuilder().build(); 1493 String channelConnectionId = "channelConnectionId-1246974660"; 1494 1495 ChannelConnection actualResponse = 1496 client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get(); 1497 Assert.assertEquals(expectedResponse, actualResponse); 1498 1499 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1500 Assert.assertEquals(1, actualRequests.size()); 1501 CreateChannelConnectionRequest actualRequest = 1502 ((CreateChannelConnectionRequest) actualRequests.get(0)); 1503 1504 Assert.assertEquals(parent, actualRequest.getParent()); 1505 Assert.assertEquals(channelConnection, actualRequest.getChannelConnection()); 1506 Assert.assertEquals(channelConnectionId, actualRequest.getChannelConnectionId()); 1507 Assert.assertTrue( 1508 channelProvider.isHeaderSent( 1509 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1510 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1511 } 1512 1513 @Test createChannelConnectionExceptionTest2()1514 public void createChannelConnectionExceptionTest2() throws Exception { 1515 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1516 mockEventarc.addException(exception); 1517 1518 try { 1519 String parent = "parent-995424086"; 1520 ChannelConnection channelConnection = ChannelConnection.newBuilder().build(); 1521 String channelConnectionId = "channelConnectionId-1246974660"; 1522 client.createChannelConnectionAsync(parent, channelConnection, channelConnectionId).get(); 1523 Assert.fail("No exception raised"); 1524 } catch (ExecutionException e) { 1525 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1526 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1527 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1528 } 1529 } 1530 1531 @Test deleteChannelConnectionTest()1532 public void deleteChannelConnectionTest() throws Exception { 1533 ChannelConnection expectedResponse = 1534 ChannelConnection.newBuilder() 1535 .setName( 1536 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]") 1537 .toString()) 1538 .setUid("uid115792") 1539 .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1540 .setCreateTime(Timestamp.newBuilder().build()) 1541 .setUpdateTime(Timestamp.newBuilder().build()) 1542 .setActivationToken("activationToken1276937859") 1543 .build(); 1544 Operation resultOperation = 1545 Operation.newBuilder() 1546 .setName("deleteChannelConnectionTest") 1547 .setDone(true) 1548 .setResponse(Any.pack(expectedResponse)) 1549 .build(); 1550 mockEventarc.addResponse(resultOperation); 1551 1552 ChannelConnectionName name = 1553 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]"); 1554 1555 ChannelConnection actualResponse = client.deleteChannelConnectionAsync(name).get(); 1556 Assert.assertEquals(expectedResponse, actualResponse); 1557 1558 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1559 Assert.assertEquals(1, actualRequests.size()); 1560 DeleteChannelConnectionRequest actualRequest = 1561 ((DeleteChannelConnectionRequest) actualRequests.get(0)); 1562 1563 Assert.assertEquals(name.toString(), actualRequest.getName()); 1564 Assert.assertTrue( 1565 channelProvider.isHeaderSent( 1566 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1567 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1568 } 1569 1570 @Test deleteChannelConnectionExceptionTest()1571 public void deleteChannelConnectionExceptionTest() throws Exception { 1572 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1573 mockEventarc.addException(exception); 1574 1575 try { 1576 ChannelConnectionName name = 1577 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]"); 1578 client.deleteChannelConnectionAsync(name).get(); 1579 Assert.fail("No exception raised"); 1580 } catch (ExecutionException e) { 1581 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1582 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1583 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1584 } 1585 } 1586 1587 @Test deleteChannelConnectionTest2()1588 public void deleteChannelConnectionTest2() throws Exception { 1589 ChannelConnection expectedResponse = 1590 ChannelConnection.newBuilder() 1591 .setName( 1592 ChannelConnectionName.of("[PROJECT]", "[LOCATION]", "[CHANNEL_CONNECTION]") 1593 .toString()) 1594 .setUid("uid115792") 1595 .setChannel(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1596 .setCreateTime(Timestamp.newBuilder().build()) 1597 .setUpdateTime(Timestamp.newBuilder().build()) 1598 .setActivationToken("activationToken1276937859") 1599 .build(); 1600 Operation resultOperation = 1601 Operation.newBuilder() 1602 .setName("deleteChannelConnectionTest") 1603 .setDone(true) 1604 .setResponse(Any.pack(expectedResponse)) 1605 .build(); 1606 mockEventarc.addResponse(resultOperation); 1607 1608 String name = "name3373707"; 1609 1610 ChannelConnection actualResponse = client.deleteChannelConnectionAsync(name).get(); 1611 Assert.assertEquals(expectedResponse, actualResponse); 1612 1613 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1614 Assert.assertEquals(1, actualRequests.size()); 1615 DeleteChannelConnectionRequest actualRequest = 1616 ((DeleteChannelConnectionRequest) actualRequests.get(0)); 1617 1618 Assert.assertEquals(name, actualRequest.getName()); 1619 Assert.assertTrue( 1620 channelProvider.isHeaderSent( 1621 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1622 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1623 } 1624 1625 @Test deleteChannelConnectionExceptionTest2()1626 public void deleteChannelConnectionExceptionTest2() throws Exception { 1627 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1628 mockEventarc.addException(exception); 1629 1630 try { 1631 String name = "name3373707"; 1632 client.deleteChannelConnectionAsync(name).get(); 1633 Assert.fail("No exception raised"); 1634 } catch (ExecutionException e) { 1635 Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); 1636 InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); 1637 Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); 1638 } 1639 } 1640 1641 @Test getGoogleChannelConfigTest()1642 public void getGoogleChannelConfigTest() throws Exception { 1643 GoogleChannelConfig expectedResponse = 1644 GoogleChannelConfig.newBuilder() 1645 .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString()) 1646 .setUpdateTime(Timestamp.newBuilder().build()) 1647 .setCryptoKeyName("cryptoKeyName1447084425") 1648 .build(); 1649 mockEventarc.addResponse(expectedResponse); 1650 1651 GoogleChannelConfigName name = GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]"); 1652 1653 GoogleChannelConfig actualResponse = client.getGoogleChannelConfig(name); 1654 Assert.assertEquals(expectedResponse, actualResponse); 1655 1656 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1657 Assert.assertEquals(1, actualRequests.size()); 1658 GetGoogleChannelConfigRequest actualRequest = 1659 ((GetGoogleChannelConfigRequest) actualRequests.get(0)); 1660 1661 Assert.assertEquals(name.toString(), actualRequest.getName()); 1662 Assert.assertTrue( 1663 channelProvider.isHeaderSent( 1664 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1665 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1666 } 1667 1668 @Test getGoogleChannelConfigExceptionTest()1669 public void getGoogleChannelConfigExceptionTest() throws Exception { 1670 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1671 mockEventarc.addException(exception); 1672 1673 try { 1674 GoogleChannelConfigName name = GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]"); 1675 client.getGoogleChannelConfig(name); 1676 Assert.fail("No exception raised"); 1677 } catch (InvalidArgumentException e) { 1678 // Expected exception. 1679 } 1680 } 1681 1682 @Test getGoogleChannelConfigTest2()1683 public void getGoogleChannelConfigTest2() throws Exception { 1684 GoogleChannelConfig expectedResponse = 1685 GoogleChannelConfig.newBuilder() 1686 .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString()) 1687 .setUpdateTime(Timestamp.newBuilder().build()) 1688 .setCryptoKeyName("cryptoKeyName1447084425") 1689 .build(); 1690 mockEventarc.addResponse(expectedResponse); 1691 1692 String name = "name3373707"; 1693 1694 GoogleChannelConfig actualResponse = client.getGoogleChannelConfig(name); 1695 Assert.assertEquals(expectedResponse, actualResponse); 1696 1697 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1698 Assert.assertEquals(1, actualRequests.size()); 1699 GetGoogleChannelConfigRequest actualRequest = 1700 ((GetGoogleChannelConfigRequest) actualRequests.get(0)); 1701 1702 Assert.assertEquals(name, actualRequest.getName()); 1703 Assert.assertTrue( 1704 channelProvider.isHeaderSent( 1705 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1706 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1707 } 1708 1709 @Test getGoogleChannelConfigExceptionTest2()1710 public void getGoogleChannelConfigExceptionTest2() throws Exception { 1711 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1712 mockEventarc.addException(exception); 1713 1714 try { 1715 String name = "name3373707"; 1716 client.getGoogleChannelConfig(name); 1717 Assert.fail("No exception raised"); 1718 } catch (InvalidArgumentException e) { 1719 // Expected exception. 1720 } 1721 } 1722 1723 @Test updateGoogleChannelConfigTest()1724 public void updateGoogleChannelConfigTest() throws Exception { 1725 GoogleChannelConfig expectedResponse = 1726 GoogleChannelConfig.newBuilder() 1727 .setName(GoogleChannelConfigName.of("[PROJECT]", "[LOCATION]").toString()) 1728 .setUpdateTime(Timestamp.newBuilder().build()) 1729 .setCryptoKeyName("cryptoKeyName1447084425") 1730 .build(); 1731 mockEventarc.addResponse(expectedResponse); 1732 1733 GoogleChannelConfig googleChannelConfig = GoogleChannelConfig.newBuilder().build(); 1734 FieldMask updateMask = FieldMask.newBuilder().build(); 1735 1736 GoogleChannelConfig actualResponse = 1737 client.updateGoogleChannelConfig(googleChannelConfig, updateMask); 1738 Assert.assertEquals(expectedResponse, actualResponse); 1739 1740 List<AbstractMessage> actualRequests = mockEventarc.getRequests(); 1741 Assert.assertEquals(1, actualRequests.size()); 1742 UpdateGoogleChannelConfigRequest actualRequest = 1743 ((UpdateGoogleChannelConfigRequest) actualRequests.get(0)); 1744 1745 Assert.assertEquals(googleChannelConfig, actualRequest.getGoogleChannelConfig()); 1746 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 1747 Assert.assertTrue( 1748 channelProvider.isHeaderSent( 1749 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1750 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1751 } 1752 1753 @Test updateGoogleChannelConfigExceptionTest()1754 public void updateGoogleChannelConfigExceptionTest() throws Exception { 1755 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1756 mockEventarc.addException(exception); 1757 1758 try { 1759 GoogleChannelConfig googleChannelConfig = GoogleChannelConfig.newBuilder().build(); 1760 FieldMask updateMask = FieldMask.newBuilder().build(); 1761 client.updateGoogleChannelConfig(googleChannelConfig, updateMask); 1762 Assert.fail("No exception raised"); 1763 } catch (InvalidArgumentException e) { 1764 // Expected exception. 1765 } 1766 } 1767 1768 @Test listLocationsTest()1769 public void listLocationsTest() throws Exception { 1770 Location responsesElement = Location.newBuilder().build(); 1771 ListLocationsResponse expectedResponse = 1772 ListLocationsResponse.newBuilder() 1773 .setNextPageToken("") 1774 .addAllLocations(Arrays.asList(responsesElement)) 1775 .build(); 1776 mockLocations.addResponse(expectedResponse); 1777 1778 ListLocationsRequest request = 1779 ListLocationsRequest.newBuilder() 1780 .setName("name3373707") 1781 .setFilter("filter-1274492040") 1782 .setPageSize(883849137) 1783 .setPageToken("pageToken873572522") 1784 .build(); 1785 1786 ListLocationsPagedResponse pagedListResponse = client.listLocations(request); 1787 1788 List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1789 1790 Assert.assertEquals(1, resources.size()); 1791 Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0)); 1792 1793 List<AbstractMessage> actualRequests = mockLocations.getRequests(); 1794 Assert.assertEquals(1, actualRequests.size()); 1795 ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0)); 1796 1797 Assert.assertEquals(request.getName(), actualRequest.getName()); 1798 Assert.assertEquals(request.getFilter(), actualRequest.getFilter()); 1799 Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); 1800 Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); 1801 Assert.assertTrue( 1802 channelProvider.isHeaderSent( 1803 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1804 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1805 } 1806 1807 @Test listLocationsExceptionTest()1808 public void listLocationsExceptionTest() throws Exception { 1809 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1810 mockLocations.addException(exception); 1811 1812 try { 1813 ListLocationsRequest request = 1814 ListLocationsRequest.newBuilder() 1815 .setName("name3373707") 1816 .setFilter("filter-1274492040") 1817 .setPageSize(883849137) 1818 .setPageToken("pageToken873572522") 1819 .build(); 1820 client.listLocations(request); 1821 Assert.fail("No exception raised"); 1822 } catch (InvalidArgumentException e) { 1823 // Expected exception. 1824 } 1825 } 1826 1827 @Test getLocationTest()1828 public void getLocationTest() throws Exception { 1829 Location expectedResponse = 1830 Location.newBuilder() 1831 .setName("name3373707") 1832 .setLocationId("locationId1541836720") 1833 .setDisplayName("displayName1714148973") 1834 .putAllLabels(new HashMap<String, String>()) 1835 .setMetadata(Any.newBuilder().build()) 1836 .build(); 1837 mockLocations.addResponse(expectedResponse); 1838 1839 GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 1840 1841 Location actualResponse = client.getLocation(request); 1842 Assert.assertEquals(expectedResponse, actualResponse); 1843 1844 List<AbstractMessage> actualRequests = mockLocations.getRequests(); 1845 Assert.assertEquals(1, actualRequests.size()); 1846 GetLocationRequest actualRequest = ((GetLocationRequest) actualRequests.get(0)); 1847 1848 Assert.assertEquals(request.getName(), actualRequest.getName()); 1849 Assert.assertTrue( 1850 channelProvider.isHeaderSent( 1851 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1852 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1853 } 1854 1855 @Test getLocationExceptionTest()1856 public void getLocationExceptionTest() throws Exception { 1857 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1858 mockLocations.addException(exception); 1859 1860 try { 1861 GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 1862 client.getLocation(request); 1863 Assert.fail("No exception raised"); 1864 } catch (InvalidArgumentException e) { 1865 // Expected exception. 1866 } 1867 } 1868 1869 @Test setIamPolicyTest()1870 public void setIamPolicyTest() throws Exception { 1871 Policy expectedResponse = 1872 Policy.newBuilder() 1873 .setVersion(351608024) 1874 .addAllBindings(new ArrayList<Binding>()) 1875 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 1876 .setEtag(ByteString.EMPTY) 1877 .build(); 1878 mockIAMPolicy.addResponse(expectedResponse); 1879 1880 SetIamPolicyRequest request = 1881 SetIamPolicyRequest.newBuilder() 1882 .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1883 .setPolicy(Policy.newBuilder().build()) 1884 .setUpdateMask(FieldMask.newBuilder().build()) 1885 .build(); 1886 1887 Policy actualResponse = client.setIamPolicy(request); 1888 Assert.assertEquals(expectedResponse, actualResponse); 1889 1890 List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests(); 1891 Assert.assertEquals(1, actualRequests.size()); 1892 SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); 1893 1894 Assert.assertEquals(request.getResource(), actualRequest.getResource()); 1895 Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); 1896 Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); 1897 Assert.assertTrue( 1898 channelProvider.isHeaderSent( 1899 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1900 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1901 } 1902 1903 @Test setIamPolicyExceptionTest()1904 public void setIamPolicyExceptionTest() throws Exception { 1905 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1906 mockIAMPolicy.addException(exception); 1907 1908 try { 1909 SetIamPolicyRequest request = 1910 SetIamPolicyRequest.newBuilder() 1911 .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1912 .setPolicy(Policy.newBuilder().build()) 1913 .setUpdateMask(FieldMask.newBuilder().build()) 1914 .build(); 1915 client.setIamPolicy(request); 1916 Assert.fail("No exception raised"); 1917 } catch (InvalidArgumentException e) { 1918 // Expected exception. 1919 } 1920 } 1921 1922 @Test getIamPolicyTest()1923 public void getIamPolicyTest() throws Exception { 1924 Policy expectedResponse = 1925 Policy.newBuilder() 1926 .setVersion(351608024) 1927 .addAllBindings(new ArrayList<Binding>()) 1928 .addAllAuditConfigs(new ArrayList<AuditConfig>()) 1929 .setEtag(ByteString.EMPTY) 1930 .build(); 1931 mockIAMPolicy.addResponse(expectedResponse); 1932 1933 GetIamPolicyRequest request = 1934 GetIamPolicyRequest.newBuilder() 1935 .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1936 .setOptions(GetPolicyOptions.newBuilder().build()) 1937 .build(); 1938 1939 Policy actualResponse = client.getIamPolicy(request); 1940 Assert.assertEquals(expectedResponse, actualResponse); 1941 1942 List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests(); 1943 Assert.assertEquals(1, actualRequests.size()); 1944 GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); 1945 1946 Assert.assertEquals(request.getResource(), actualRequest.getResource()); 1947 Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); 1948 Assert.assertTrue( 1949 channelProvider.isHeaderSent( 1950 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1951 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1952 } 1953 1954 @Test getIamPolicyExceptionTest()1955 public void getIamPolicyExceptionTest() throws Exception { 1956 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1957 mockIAMPolicy.addException(exception); 1958 1959 try { 1960 GetIamPolicyRequest request = 1961 GetIamPolicyRequest.newBuilder() 1962 .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1963 .setOptions(GetPolicyOptions.newBuilder().build()) 1964 .build(); 1965 client.getIamPolicy(request); 1966 Assert.fail("No exception raised"); 1967 } catch (InvalidArgumentException e) { 1968 // Expected exception. 1969 } 1970 } 1971 1972 @Test testIamPermissionsTest()1973 public void testIamPermissionsTest() throws Exception { 1974 TestIamPermissionsResponse expectedResponse = 1975 TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build(); 1976 mockIAMPolicy.addResponse(expectedResponse); 1977 1978 TestIamPermissionsRequest request = 1979 TestIamPermissionsRequest.newBuilder() 1980 .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 1981 .addAllPermissions(new ArrayList<String>()) 1982 .build(); 1983 1984 TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); 1985 Assert.assertEquals(expectedResponse, actualResponse); 1986 1987 List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests(); 1988 Assert.assertEquals(1, actualRequests.size()); 1989 TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); 1990 1991 Assert.assertEquals(request.getResource(), actualRequest.getResource()); 1992 Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); 1993 Assert.assertTrue( 1994 channelProvider.isHeaderSent( 1995 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1996 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1997 } 1998 1999 @Test testIamPermissionsExceptionTest()2000 public void testIamPermissionsExceptionTest() throws Exception { 2001 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 2002 mockIAMPolicy.addException(exception); 2003 2004 try { 2005 TestIamPermissionsRequest request = 2006 TestIamPermissionsRequest.newBuilder() 2007 .setResource(ChannelName.of("[PROJECT]", "[LOCATION]", "[CHANNEL]").toString()) 2008 .addAllPermissions(new ArrayList<String>()) 2009 .build(); 2010 client.testIamPermissions(request); 2011 Assert.fail("No exception raised"); 2012 } catch (InvalidArgumentException e) { 2013 // Expected exception. 2014 } 2015 } 2016 } 2017