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 io.grafeas.v1; 18 19 import static io.grafeas.v1.GrafeasClient.ListNoteOccurrencesPagedResponse; 20 import static io.grafeas.v1.GrafeasClient.ListNotesPagedResponse; 21 import static io.grafeas.v1.GrafeasClient.ListOccurrencesPagedResponse; 22 23 import com.google.api.gax.core.NoCredentialsProvider; 24 import com.google.api.gax.grpc.GaxGrpcProperties; 25 import com.google.api.gax.grpc.testing.LocalChannelProvider; 26 import com.google.api.gax.grpc.testing.MockGrpcService; 27 import com.google.api.gax.grpc.testing.MockServiceHelper; 28 import com.google.api.gax.rpc.ApiClientHeaderProvider; 29 import com.google.api.gax.rpc.InvalidArgumentException; 30 import com.google.common.collect.Lists; 31 import com.google.protobuf.AbstractMessage; 32 import com.google.protobuf.Empty; 33 import com.google.protobuf.FieldMask; 34 import com.google.protobuf.Timestamp; 35 import io.grpc.StatusRuntimeException; 36 import java.io.IOException; 37 import java.util.ArrayList; 38 import java.util.Arrays; 39 import java.util.HashMap; 40 import java.util.List; 41 import java.util.Map; 42 import java.util.UUID; 43 import javax.annotation.Generated; 44 import org.junit.After; 45 import org.junit.AfterClass; 46 import org.junit.Assert; 47 import org.junit.Before; 48 import org.junit.BeforeClass; 49 import org.junit.Test; 50 51 @Generated("by gapic-generator-java") 52 public class GrafeasClientTest { 53 private static MockGrafeas mockGrafeas; 54 private static MockServiceHelper mockServiceHelper; 55 private LocalChannelProvider channelProvider; 56 private GrafeasClient client; 57 58 @BeforeClass startStaticServer()59 public static void startStaticServer() { 60 mockGrafeas = new MockGrafeas(); 61 mockServiceHelper = 62 new MockServiceHelper( 63 UUID.randomUUID().toString(), Arrays.<MockGrpcService>asList(mockGrafeas)); 64 mockServiceHelper.start(); 65 } 66 67 @AfterClass stopServer()68 public static void stopServer() { 69 mockServiceHelper.stop(); 70 } 71 72 @Before setUp()73 public void setUp() throws IOException { 74 mockServiceHelper.reset(); 75 channelProvider = mockServiceHelper.createChannelProvider(); 76 GrafeasSettings settings = 77 GrafeasSettings.newBuilder() 78 .setTransportChannelProvider(channelProvider) 79 .setCredentialsProvider(NoCredentialsProvider.create()) 80 .build(); 81 client = GrafeasClient.create(settings); 82 } 83 84 @After tearDown()85 public void tearDown() throws Exception { 86 client.close(); 87 } 88 89 @Test getOccurrenceTest()90 public void getOccurrenceTest() throws Exception { 91 Occurrence expectedResponse = 92 Occurrence.newBuilder() 93 .setName(OccurrenceName.of("[PROJECT]", "[OCCURRENCE]").toString()) 94 .setResourceUri("resourceUri1234527870") 95 .setNoteName("noteName1580946845") 96 .setKind(NoteKind.forNumber(0)) 97 .setRemediation("remediation779381797") 98 .setCreateTime(Timestamp.newBuilder().build()) 99 .setUpdateTime(Timestamp.newBuilder().build()) 100 .setEnvelope(Envelope.newBuilder().build()) 101 .build(); 102 mockGrafeas.addResponse(expectedResponse); 103 104 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 105 106 Occurrence actualResponse = client.getOccurrence(name); 107 Assert.assertEquals(expectedResponse, actualResponse); 108 109 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 110 Assert.assertEquals(1, actualRequests.size()); 111 GetOccurrenceRequest actualRequest = ((GetOccurrenceRequest) actualRequests.get(0)); 112 113 Assert.assertEquals(name.toString(), actualRequest.getName()); 114 Assert.assertTrue( 115 channelProvider.isHeaderSent( 116 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 117 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 118 } 119 120 @Test getOccurrenceExceptionTest()121 public void getOccurrenceExceptionTest() throws Exception { 122 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 123 mockGrafeas.addException(exception); 124 125 try { 126 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 127 client.getOccurrence(name); 128 Assert.fail("No exception raised"); 129 } catch (InvalidArgumentException e) { 130 // Expected exception. 131 } 132 } 133 134 @Test getOccurrenceTest2()135 public void getOccurrenceTest2() throws Exception { 136 Occurrence expectedResponse = 137 Occurrence.newBuilder() 138 .setName(OccurrenceName.of("[PROJECT]", "[OCCURRENCE]").toString()) 139 .setResourceUri("resourceUri1234527870") 140 .setNoteName("noteName1580946845") 141 .setKind(NoteKind.forNumber(0)) 142 .setRemediation("remediation779381797") 143 .setCreateTime(Timestamp.newBuilder().build()) 144 .setUpdateTime(Timestamp.newBuilder().build()) 145 .setEnvelope(Envelope.newBuilder().build()) 146 .build(); 147 mockGrafeas.addResponse(expectedResponse); 148 149 String name = "name3373707"; 150 151 Occurrence actualResponse = client.getOccurrence(name); 152 Assert.assertEquals(expectedResponse, actualResponse); 153 154 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 155 Assert.assertEquals(1, actualRequests.size()); 156 GetOccurrenceRequest actualRequest = ((GetOccurrenceRequest) actualRequests.get(0)); 157 158 Assert.assertEquals(name, actualRequest.getName()); 159 Assert.assertTrue( 160 channelProvider.isHeaderSent( 161 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 162 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 163 } 164 165 @Test getOccurrenceExceptionTest2()166 public void getOccurrenceExceptionTest2() throws Exception { 167 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 168 mockGrafeas.addException(exception); 169 170 try { 171 String name = "name3373707"; 172 client.getOccurrence(name); 173 Assert.fail("No exception raised"); 174 } catch (InvalidArgumentException e) { 175 // Expected exception. 176 } 177 } 178 179 @Test listOccurrencesTest()180 public void listOccurrencesTest() throws Exception { 181 Occurrence responsesElement = Occurrence.newBuilder().build(); 182 ListOccurrencesResponse expectedResponse = 183 ListOccurrencesResponse.newBuilder() 184 .setNextPageToken("") 185 .addAllOccurrences(Arrays.asList(responsesElement)) 186 .build(); 187 mockGrafeas.addResponse(expectedResponse); 188 189 ProjectName parent = ProjectName.of("[PROJECT]"); 190 String filter = "filter-1274492040"; 191 192 ListOccurrencesPagedResponse pagedListResponse = client.listOccurrences(parent, filter); 193 194 List<Occurrence> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 195 196 Assert.assertEquals(1, resources.size()); 197 Assert.assertEquals(expectedResponse.getOccurrencesList().get(0), resources.get(0)); 198 199 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 200 Assert.assertEquals(1, actualRequests.size()); 201 ListOccurrencesRequest actualRequest = ((ListOccurrencesRequest) actualRequests.get(0)); 202 203 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 204 Assert.assertEquals(filter, actualRequest.getFilter()); 205 Assert.assertTrue( 206 channelProvider.isHeaderSent( 207 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 208 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 209 } 210 211 @Test listOccurrencesExceptionTest()212 public void listOccurrencesExceptionTest() throws Exception { 213 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 214 mockGrafeas.addException(exception); 215 216 try { 217 ProjectName parent = ProjectName.of("[PROJECT]"); 218 String filter = "filter-1274492040"; 219 client.listOccurrences(parent, filter); 220 Assert.fail("No exception raised"); 221 } catch (InvalidArgumentException e) { 222 // Expected exception. 223 } 224 } 225 226 @Test listOccurrencesTest2()227 public void listOccurrencesTest2() throws Exception { 228 Occurrence responsesElement = Occurrence.newBuilder().build(); 229 ListOccurrencesResponse expectedResponse = 230 ListOccurrencesResponse.newBuilder() 231 .setNextPageToken("") 232 .addAllOccurrences(Arrays.asList(responsesElement)) 233 .build(); 234 mockGrafeas.addResponse(expectedResponse); 235 236 String parent = "parent-995424086"; 237 String filter = "filter-1274492040"; 238 239 ListOccurrencesPagedResponse pagedListResponse = client.listOccurrences(parent, filter); 240 241 List<Occurrence> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 242 243 Assert.assertEquals(1, resources.size()); 244 Assert.assertEquals(expectedResponse.getOccurrencesList().get(0), resources.get(0)); 245 246 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 247 Assert.assertEquals(1, actualRequests.size()); 248 ListOccurrencesRequest actualRequest = ((ListOccurrencesRequest) actualRequests.get(0)); 249 250 Assert.assertEquals(parent, actualRequest.getParent()); 251 Assert.assertEquals(filter, actualRequest.getFilter()); 252 Assert.assertTrue( 253 channelProvider.isHeaderSent( 254 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 255 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 256 } 257 258 @Test listOccurrencesExceptionTest2()259 public void listOccurrencesExceptionTest2() throws Exception { 260 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 261 mockGrafeas.addException(exception); 262 263 try { 264 String parent = "parent-995424086"; 265 String filter = "filter-1274492040"; 266 client.listOccurrences(parent, filter); 267 Assert.fail("No exception raised"); 268 } catch (InvalidArgumentException e) { 269 // Expected exception. 270 } 271 } 272 273 @Test deleteOccurrenceTest()274 public void deleteOccurrenceTest() throws Exception { 275 Empty expectedResponse = Empty.newBuilder().build(); 276 mockGrafeas.addResponse(expectedResponse); 277 278 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 279 280 client.deleteOccurrence(name); 281 282 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 283 Assert.assertEquals(1, actualRequests.size()); 284 DeleteOccurrenceRequest actualRequest = ((DeleteOccurrenceRequest) actualRequests.get(0)); 285 286 Assert.assertEquals(name.toString(), actualRequest.getName()); 287 Assert.assertTrue( 288 channelProvider.isHeaderSent( 289 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 290 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 291 } 292 293 @Test deleteOccurrenceExceptionTest()294 public void deleteOccurrenceExceptionTest() throws Exception { 295 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 296 mockGrafeas.addException(exception); 297 298 try { 299 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 300 client.deleteOccurrence(name); 301 Assert.fail("No exception raised"); 302 } catch (InvalidArgumentException e) { 303 // Expected exception. 304 } 305 } 306 307 @Test deleteOccurrenceTest2()308 public void deleteOccurrenceTest2() throws Exception { 309 Empty expectedResponse = Empty.newBuilder().build(); 310 mockGrafeas.addResponse(expectedResponse); 311 312 String name = "name3373707"; 313 314 client.deleteOccurrence(name); 315 316 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 317 Assert.assertEquals(1, actualRequests.size()); 318 DeleteOccurrenceRequest actualRequest = ((DeleteOccurrenceRequest) actualRequests.get(0)); 319 320 Assert.assertEquals(name, actualRequest.getName()); 321 Assert.assertTrue( 322 channelProvider.isHeaderSent( 323 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 324 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 325 } 326 327 @Test deleteOccurrenceExceptionTest2()328 public void deleteOccurrenceExceptionTest2() throws Exception { 329 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 330 mockGrafeas.addException(exception); 331 332 try { 333 String name = "name3373707"; 334 client.deleteOccurrence(name); 335 Assert.fail("No exception raised"); 336 } catch (InvalidArgumentException e) { 337 // Expected exception. 338 } 339 } 340 341 @Test createOccurrenceTest()342 public void createOccurrenceTest() throws Exception { 343 Occurrence expectedResponse = 344 Occurrence.newBuilder() 345 .setName(OccurrenceName.of("[PROJECT]", "[OCCURRENCE]").toString()) 346 .setResourceUri("resourceUri1234527870") 347 .setNoteName("noteName1580946845") 348 .setKind(NoteKind.forNumber(0)) 349 .setRemediation("remediation779381797") 350 .setCreateTime(Timestamp.newBuilder().build()) 351 .setUpdateTime(Timestamp.newBuilder().build()) 352 .setEnvelope(Envelope.newBuilder().build()) 353 .build(); 354 mockGrafeas.addResponse(expectedResponse); 355 356 ProjectName parent = ProjectName.of("[PROJECT]"); 357 Occurrence occurrence = Occurrence.newBuilder().build(); 358 359 Occurrence actualResponse = client.createOccurrence(parent, occurrence); 360 Assert.assertEquals(expectedResponse, actualResponse); 361 362 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 363 Assert.assertEquals(1, actualRequests.size()); 364 CreateOccurrenceRequest actualRequest = ((CreateOccurrenceRequest) actualRequests.get(0)); 365 366 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 367 Assert.assertEquals(occurrence, actualRequest.getOccurrence()); 368 Assert.assertTrue( 369 channelProvider.isHeaderSent( 370 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 371 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 372 } 373 374 @Test createOccurrenceExceptionTest()375 public void createOccurrenceExceptionTest() throws Exception { 376 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 377 mockGrafeas.addException(exception); 378 379 try { 380 ProjectName parent = ProjectName.of("[PROJECT]"); 381 Occurrence occurrence = Occurrence.newBuilder().build(); 382 client.createOccurrence(parent, occurrence); 383 Assert.fail("No exception raised"); 384 } catch (InvalidArgumentException e) { 385 // Expected exception. 386 } 387 } 388 389 @Test createOccurrenceTest2()390 public void createOccurrenceTest2() throws Exception { 391 Occurrence expectedResponse = 392 Occurrence.newBuilder() 393 .setName(OccurrenceName.of("[PROJECT]", "[OCCURRENCE]").toString()) 394 .setResourceUri("resourceUri1234527870") 395 .setNoteName("noteName1580946845") 396 .setKind(NoteKind.forNumber(0)) 397 .setRemediation("remediation779381797") 398 .setCreateTime(Timestamp.newBuilder().build()) 399 .setUpdateTime(Timestamp.newBuilder().build()) 400 .setEnvelope(Envelope.newBuilder().build()) 401 .build(); 402 mockGrafeas.addResponse(expectedResponse); 403 404 String parent = "parent-995424086"; 405 Occurrence occurrence = Occurrence.newBuilder().build(); 406 407 Occurrence actualResponse = client.createOccurrence(parent, occurrence); 408 Assert.assertEquals(expectedResponse, actualResponse); 409 410 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 411 Assert.assertEquals(1, actualRequests.size()); 412 CreateOccurrenceRequest actualRequest = ((CreateOccurrenceRequest) actualRequests.get(0)); 413 414 Assert.assertEquals(parent, actualRequest.getParent()); 415 Assert.assertEquals(occurrence, actualRequest.getOccurrence()); 416 Assert.assertTrue( 417 channelProvider.isHeaderSent( 418 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 419 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 420 } 421 422 @Test createOccurrenceExceptionTest2()423 public void createOccurrenceExceptionTest2() throws Exception { 424 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 425 mockGrafeas.addException(exception); 426 427 try { 428 String parent = "parent-995424086"; 429 Occurrence occurrence = Occurrence.newBuilder().build(); 430 client.createOccurrence(parent, occurrence); 431 Assert.fail("No exception raised"); 432 } catch (InvalidArgumentException e) { 433 // Expected exception. 434 } 435 } 436 437 @Test batchCreateOccurrencesTest()438 public void batchCreateOccurrencesTest() throws Exception { 439 BatchCreateOccurrencesResponse expectedResponse = 440 BatchCreateOccurrencesResponse.newBuilder() 441 .addAllOccurrences(new ArrayList<Occurrence>()) 442 .build(); 443 mockGrafeas.addResponse(expectedResponse); 444 445 ProjectName parent = ProjectName.of("[PROJECT]"); 446 List<Occurrence> occurrences = new ArrayList<>(); 447 448 BatchCreateOccurrencesResponse actualResponse = 449 client.batchCreateOccurrences(parent, occurrences); 450 Assert.assertEquals(expectedResponse, actualResponse); 451 452 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 453 Assert.assertEquals(1, actualRequests.size()); 454 BatchCreateOccurrencesRequest actualRequest = 455 ((BatchCreateOccurrencesRequest) actualRequests.get(0)); 456 457 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 458 Assert.assertEquals(occurrences, actualRequest.getOccurrencesList()); 459 Assert.assertTrue( 460 channelProvider.isHeaderSent( 461 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 462 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 463 } 464 465 @Test batchCreateOccurrencesExceptionTest()466 public void batchCreateOccurrencesExceptionTest() throws Exception { 467 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 468 mockGrafeas.addException(exception); 469 470 try { 471 ProjectName parent = ProjectName.of("[PROJECT]"); 472 List<Occurrence> occurrences = new ArrayList<>(); 473 client.batchCreateOccurrences(parent, occurrences); 474 Assert.fail("No exception raised"); 475 } catch (InvalidArgumentException e) { 476 // Expected exception. 477 } 478 } 479 480 @Test batchCreateOccurrencesTest2()481 public void batchCreateOccurrencesTest2() throws Exception { 482 BatchCreateOccurrencesResponse expectedResponse = 483 BatchCreateOccurrencesResponse.newBuilder() 484 .addAllOccurrences(new ArrayList<Occurrence>()) 485 .build(); 486 mockGrafeas.addResponse(expectedResponse); 487 488 String parent = "parent-995424086"; 489 List<Occurrence> occurrences = new ArrayList<>(); 490 491 BatchCreateOccurrencesResponse actualResponse = 492 client.batchCreateOccurrences(parent, occurrences); 493 Assert.assertEquals(expectedResponse, actualResponse); 494 495 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 496 Assert.assertEquals(1, actualRequests.size()); 497 BatchCreateOccurrencesRequest actualRequest = 498 ((BatchCreateOccurrencesRequest) actualRequests.get(0)); 499 500 Assert.assertEquals(parent, actualRequest.getParent()); 501 Assert.assertEquals(occurrences, actualRequest.getOccurrencesList()); 502 Assert.assertTrue( 503 channelProvider.isHeaderSent( 504 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 505 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 506 } 507 508 @Test batchCreateOccurrencesExceptionTest2()509 public void batchCreateOccurrencesExceptionTest2() throws Exception { 510 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 511 mockGrafeas.addException(exception); 512 513 try { 514 String parent = "parent-995424086"; 515 List<Occurrence> occurrences = new ArrayList<>(); 516 client.batchCreateOccurrences(parent, occurrences); 517 Assert.fail("No exception raised"); 518 } catch (InvalidArgumentException e) { 519 // Expected exception. 520 } 521 } 522 523 @Test updateOccurrenceTest()524 public void updateOccurrenceTest() throws Exception { 525 Occurrence expectedResponse = 526 Occurrence.newBuilder() 527 .setName(OccurrenceName.of("[PROJECT]", "[OCCURRENCE]").toString()) 528 .setResourceUri("resourceUri1234527870") 529 .setNoteName("noteName1580946845") 530 .setKind(NoteKind.forNumber(0)) 531 .setRemediation("remediation779381797") 532 .setCreateTime(Timestamp.newBuilder().build()) 533 .setUpdateTime(Timestamp.newBuilder().build()) 534 .setEnvelope(Envelope.newBuilder().build()) 535 .build(); 536 mockGrafeas.addResponse(expectedResponse); 537 538 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 539 Occurrence occurrence = Occurrence.newBuilder().build(); 540 FieldMask updateMask = FieldMask.newBuilder().build(); 541 542 Occurrence actualResponse = client.updateOccurrence(name, occurrence, updateMask); 543 Assert.assertEquals(expectedResponse, actualResponse); 544 545 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 546 Assert.assertEquals(1, actualRequests.size()); 547 UpdateOccurrenceRequest actualRequest = ((UpdateOccurrenceRequest) actualRequests.get(0)); 548 549 Assert.assertEquals(name.toString(), actualRequest.getName()); 550 Assert.assertEquals(occurrence, actualRequest.getOccurrence()); 551 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 552 Assert.assertTrue( 553 channelProvider.isHeaderSent( 554 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 555 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 556 } 557 558 @Test updateOccurrenceExceptionTest()559 public void updateOccurrenceExceptionTest() throws Exception { 560 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 561 mockGrafeas.addException(exception); 562 563 try { 564 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 565 Occurrence occurrence = Occurrence.newBuilder().build(); 566 FieldMask updateMask = FieldMask.newBuilder().build(); 567 client.updateOccurrence(name, occurrence, updateMask); 568 Assert.fail("No exception raised"); 569 } catch (InvalidArgumentException e) { 570 // Expected exception. 571 } 572 } 573 574 @Test updateOccurrenceTest2()575 public void updateOccurrenceTest2() throws Exception { 576 Occurrence expectedResponse = 577 Occurrence.newBuilder() 578 .setName(OccurrenceName.of("[PROJECT]", "[OCCURRENCE]").toString()) 579 .setResourceUri("resourceUri1234527870") 580 .setNoteName("noteName1580946845") 581 .setKind(NoteKind.forNumber(0)) 582 .setRemediation("remediation779381797") 583 .setCreateTime(Timestamp.newBuilder().build()) 584 .setUpdateTime(Timestamp.newBuilder().build()) 585 .setEnvelope(Envelope.newBuilder().build()) 586 .build(); 587 mockGrafeas.addResponse(expectedResponse); 588 589 String name = "name3373707"; 590 Occurrence occurrence = Occurrence.newBuilder().build(); 591 FieldMask updateMask = FieldMask.newBuilder().build(); 592 593 Occurrence actualResponse = client.updateOccurrence(name, occurrence, updateMask); 594 Assert.assertEquals(expectedResponse, actualResponse); 595 596 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 597 Assert.assertEquals(1, actualRequests.size()); 598 UpdateOccurrenceRequest actualRequest = ((UpdateOccurrenceRequest) actualRequests.get(0)); 599 600 Assert.assertEquals(name, actualRequest.getName()); 601 Assert.assertEquals(occurrence, actualRequest.getOccurrence()); 602 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 603 Assert.assertTrue( 604 channelProvider.isHeaderSent( 605 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 606 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 607 } 608 609 @Test updateOccurrenceExceptionTest2()610 public void updateOccurrenceExceptionTest2() throws Exception { 611 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 612 mockGrafeas.addException(exception); 613 614 try { 615 String name = "name3373707"; 616 Occurrence occurrence = Occurrence.newBuilder().build(); 617 FieldMask updateMask = FieldMask.newBuilder().build(); 618 client.updateOccurrence(name, occurrence, updateMask); 619 Assert.fail("No exception raised"); 620 } catch (InvalidArgumentException e) { 621 // Expected exception. 622 } 623 } 624 625 @Test getOccurrenceNoteTest()626 public void getOccurrenceNoteTest() throws Exception { 627 Note expectedResponse = 628 Note.newBuilder() 629 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 630 .setShortDescription("shortDescription1951089120") 631 .setLongDescription("longDescription1763753952") 632 .setKind(NoteKind.forNumber(0)) 633 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 634 .setExpirationTime(Timestamp.newBuilder().build()) 635 .setCreateTime(Timestamp.newBuilder().build()) 636 .setUpdateTime(Timestamp.newBuilder().build()) 637 .addAllRelatedNoteNames(new ArrayList<String>()) 638 .build(); 639 mockGrafeas.addResponse(expectedResponse); 640 641 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 642 643 Note actualResponse = client.getOccurrenceNote(name); 644 Assert.assertEquals(expectedResponse, actualResponse); 645 646 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 647 Assert.assertEquals(1, actualRequests.size()); 648 GetOccurrenceNoteRequest actualRequest = ((GetOccurrenceNoteRequest) actualRequests.get(0)); 649 650 Assert.assertEquals(name.toString(), actualRequest.getName()); 651 Assert.assertTrue( 652 channelProvider.isHeaderSent( 653 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 654 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 655 } 656 657 @Test getOccurrenceNoteExceptionTest()658 public void getOccurrenceNoteExceptionTest() throws Exception { 659 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 660 mockGrafeas.addException(exception); 661 662 try { 663 OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]"); 664 client.getOccurrenceNote(name); 665 Assert.fail("No exception raised"); 666 } catch (InvalidArgumentException e) { 667 // Expected exception. 668 } 669 } 670 671 @Test getOccurrenceNoteTest2()672 public void getOccurrenceNoteTest2() throws Exception { 673 Note expectedResponse = 674 Note.newBuilder() 675 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 676 .setShortDescription("shortDescription1951089120") 677 .setLongDescription("longDescription1763753952") 678 .setKind(NoteKind.forNumber(0)) 679 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 680 .setExpirationTime(Timestamp.newBuilder().build()) 681 .setCreateTime(Timestamp.newBuilder().build()) 682 .setUpdateTime(Timestamp.newBuilder().build()) 683 .addAllRelatedNoteNames(new ArrayList<String>()) 684 .build(); 685 mockGrafeas.addResponse(expectedResponse); 686 687 String name = "name3373707"; 688 689 Note actualResponse = client.getOccurrenceNote(name); 690 Assert.assertEquals(expectedResponse, actualResponse); 691 692 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 693 Assert.assertEquals(1, actualRequests.size()); 694 GetOccurrenceNoteRequest actualRequest = ((GetOccurrenceNoteRequest) actualRequests.get(0)); 695 696 Assert.assertEquals(name, actualRequest.getName()); 697 Assert.assertTrue( 698 channelProvider.isHeaderSent( 699 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 700 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 701 } 702 703 @Test getOccurrenceNoteExceptionTest2()704 public void getOccurrenceNoteExceptionTest2() throws Exception { 705 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 706 mockGrafeas.addException(exception); 707 708 try { 709 String name = "name3373707"; 710 client.getOccurrenceNote(name); 711 Assert.fail("No exception raised"); 712 } catch (InvalidArgumentException e) { 713 // Expected exception. 714 } 715 } 716 717 @Test getNoteTest()718 public void getNoteTest() throws Exception { 719 Note expectedResponse = 720 Note.newBuilder() 721 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 722 .setShortDescription("shortDescription1951089120") 723 .setLongDescription("longDescription1763753952") 724 .setKind(NoteKind.forNumber(0)) 725 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 726 .setExpirationTime(Timestamp.newBuilder().build()) 727 .setCreateTime(Timestamp.newBuilder().build()) 728 .setUpdateTime(Timestamp.newBuilder().build()) 729 .addAllRelatedNoteNames(new ArrayList<String>()) 730 .build(); 731 mockGrafeas.addResponse(expectedResponse); 732 733 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 734 735 Note actualResponse = client.getNote(name); 736 Assert.assertEquals(expectedResponse, actualResponse); 737 738 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 739 Assert.assertEquals(1, actualRequests.size()); 740 GetNoteRequest actualRequest = ((GetNoteRequest) actualRequests.get(0)); 741 742 Assert.assertEquals(name.toString(), actualRequest.getName()); 743 Assert.assertTrue( 744 channelProvider.isHeaderSent( 745 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 746 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 747 } 748 749 @Test getNoteExceptionTest()750 public void getNoteExceptionTest() throws Exception { 751 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 752 mockGrafeas.addException(exception); 753 754 try { 755 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 756 client.getNote(name); 757 Assert.fail("No exception raised"); 758 } catch (InvalidArgumentException e) { 759 // Expected exception. 760 } 761 } 762 763 @Test getNoteTest2()764 public void getNoteTest2() throws Exception { 765 Note expectedResponse = 766 Note.newBuilder() 767 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 768 .setShortDescription("shortDescription1951089120") 769 .setLongDescription("longDescription1763753952") 770 .setKind(NoteKind.forNumber(0)) 771 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 772 .setExpirationTime(Timestamp.newBuilder().build()) 773 .setCreateTime(Timestamp.newBuilder().build()) 774 .setUpdateTime(Timestamp.newBuilder().build()) 775 .addAllRelatedNoteNames(new ArrayList<String>()) 776 .build(); 777 mockGrafeas.addResponse(expectedResponse); 778 779 String name = "name3373707"; 780 781 Note actualResponse = client.getNote(name); 782 Assert.assertEquals(expectedResponse, actualResponse); 783 784 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 785 Assert.assertEquals(1, actualRequests.size()); 786 GetNoteRequest actualRequest = ((GetNoteRequest) actualRequests.get(0)); 787 788 Assert.assertEquals(name, actualRequest.getName()); 789 Assert.assertTrue( 790 channelProvider.isHeaderSent( 791 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 792 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 793 } 794 795 @Test getNoteExceptionTest2()796 public void getNoteExceptionTest2() throws Exception { 797 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 798 mockGrafeas.addException(exception); 799 800 try { 801 String name = "name3373707"; 802 client.getNote(name); 803 Assert.fail("No exception raised"); 804 } catch (InvalidArgumentException e) { 805 // Expected exception. 806 } 807 } 808 809 @Test listNotesTest()810 public void listNotesTest() throws Exception { 811 Note responsesElement = Note.newBuilder().build(); 812 ListNotesResponse expectedResponse = 813 ListNotesResponse.newBuilder() 814 .setNextPageToken("") 815 .addAllNotes(Arrays.asList(responsesElement)) 816 .build(); 817 mockGrafeas.addResponse(expectedResponse); 818 819 ProjectName parent = ProjectName.of("[PROJECT]"); 820 String filter = "filter-1274492040"; 821 822 ListNotesPagedResponse pagedListResponse = client.listNotes(parent, filter); 823 824 List<Note> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 825 826 Assert.assertEquals(1, resources.size()); 827 Assert.assertEquals(expectedResponse.getNotesList().get(0), resources.get(0)); 828 829 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 830 Assert.assertEquals(1, actualRequests.size()); 831 ListNotesRequest actualRequest = ((ListNotesRequest) actualRequests.get(0)); 832 833 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 834 Assert.assertEquals(filter, actualRequest.getFilter()); 835 Assert.assertTrue( 836 channelProvider.isHeaderSent( 837 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 838 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 839 } 840 841 @Test listNotesExceptionTest()842 public void listNotesExceptionTest() throws Exception { 843 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 844 mockGrafeas.addException(exception); 845 846 try { 847 ProjectName parent = ProjectName.of("[PROJECT]"); 848 String filter = "filter-1274492040"; 849 client.listNotes(parent, filter); 850 Assert.fail("No exception raised"); 851 } catch (InvalidArgumentException e) { 852 // Expected exception. 853 } 854 } 855 856 @Test listNotesTest2()857 public void listNotesTest2() throws Exception { 858 Note responsesElement = Note.newBuilder().build(); 859 ListNotesResponse expectedResponse = 860 ListNotesResponse.newBuilder() 861 .setNextPageToken("") 862 .addAllNotes(Arrays.asList(responsesElement)) 863 .build(); 864 mockGrafeas.addResponse(expectedResponse); 865 866 String parent = "parent-995424086"; 867 String filter = "filter-1274492040"; 868 869 ListNotesPagedResponse pagedListResponse = client.listNotes(parent, filter); 870 871 List<Note> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 872 873 Assert.assertEquals(1, resources.size()); 874 Assert.assertEquals(expectedResponse.getNotesList().get(0), resources.get(0)); 875 876 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 877 Assert.assertEquals(1, actualRequests.size()); 878 ListNotesRequest actualRequest = ((ListNotesRequest) actualRequests.get(0)); 879 880 Assert.assertEquals(parent, actualRequest.getParent()); 881 Assert.assertEquals(filter, actualRequest.getFilter()); 882 Assert.assertTrue( 883 channelProvider.isHeaderSent( 884 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 885 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 886 } 887 888 @Test listNotesExceptionTest2()889 public void listNotesExceptionTest2() throws Exception { 890 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 891 mockGrafeas.addException(exception); 892 893 try { 894 String parent = "parent-995424086"; 895 String filter = "filter-1274492040"; 896 client.listNotes(parent, filter); 897 Assert.fail("No exception raised"); 898 } catch (InvalidArgumentException e) { 899 // Expected exception. 900 } 901 } 902 903 @Test deleteNoteTest()904 public void deleteNoteTest() throws Exception { 905 Empty expectedResponse = Empty.newBuilder().build(); 906 mockGrafeas.addResponse(expectedResponse); 907 908 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 909 910 client.deleteNote(name); 911 912 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 913 Assert.assertEquals(1, actualRequests.size()); 914 DeleteNoteRequest actualRequest = ((DeleteNoteRequest) actualRequests.get(0)); 915 916 Assert.assertEquals(name.toString(), actualRequest.getName()); 917 Assert.assertTrue( 918 channelProvider.isHeaderSent( 919 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 920 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 921 } 922 923 @Test deleteNoteExceptionTest()924 public void deleteNoteExceptionTest() throws Exception { 925 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 926 mockGrafeas.addException(exception); 927 928 try { 929 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 930 client.deleteNote(name); 931 Assert.fail("No exception raised"); 932 } catch (InvalidArgumentException e) { 933 // Expected exception. 934 } 935 } 936 937 @Test deleteNoteTest2()938 public void deleteNoteTest2() throws Exception { 939 Empty expectedResponse = Empty.newBuilder().build(); 940 mockGrafeas.addResponse(expectedResponse); 941 942 String name = "name3373707"; 943 944 client.deleteNote(name); 945 946 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 947 Assert.assertEquals(1, actualRequests.size()); 948 DeleteNoteRequest actualRequest = ((DeleteNoteRequest) actualRequests.get(0)); 949 950 Assert.assertEquals(name, actualRequest.getName()); 951 Assert.assertTrue( 952 channelProvider.isHeaderSent( 953 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 954 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 955 } 956 957 @Test deleteNoteExceptionTest2()958 public void deleteNoteExceptionTest2() throws Exception { 959 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 960 mockGrafeas.addException(exception); 961 962 try { 963 String name = "name3373707"; 964 client.deleteNote(name); 965 Assert.fail("No exception raised"); 966 } catch (InvalidArgumentException e) { 967 // Expected exception. 968 } 969 } 970 971 @Test createNoteTest()972 public void createNoteTest() throws Exception { 973 Note expectedResponse = 974 Note.newBuilder() 975 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 976 .setShortDescription("shortDescription1951089120") 977 .setLongDescription("longDescription1763753952") 978 .setKind(NoteKind.forNumber(0)) 979 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 980 .setExpirationTime(Timestamp.newBuilder().build()) 981 .setCreateTime(Timestamp.newBuilder().build()) 982 .setUpdateTime(Timestamp.newBuilder().build()) 983 .addAllRelatedNoteNames(new ArrayList<String>()) 984 .build(); 985 mockGrafeas.addResponse(expectedResponse); 986 987 ProjectName parent = ProjectName.of("[PROJECT]"); 988 String noteId = "noteId-1039694675"; 989 Note note = Note.newBuilder().build(); 990 991 Note actualResponse = client.createNote(parent, noteId, note); 992 Assert.assertEquals(expectedResponse, actualResponse); 993 994 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 995 Assert.assertEquals(1, actualRequests.size()); 996 CreateNoteRequest actualRequest = ((CreateNoteRequest) actualRequests.get(0)); 997 998 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 999 Assert.assertEquals(noteId, actualRequest.getNoteId()); 1000 Assert.assertEquals(note, actualRequest.getNote()); 1001 Assert.assertTrue( 1002 channelProvider.isHeaderSent( 1003 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1004 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1005 } 1006 1007 @Test createNoteExceptionTest()1008 public void createNoteExceptionTest() throws Exception { 1009 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1010 mockGrafeas.addException(exception); 1011 1012 try { 1013 ProjectName parent = ProjectName.of("[PROJECT]"); 1014 String noteId = "noteId-1039694675"; 1015 Note note = Note.newBuilder().build(); 1016 client.createNote(parent, noteId, note); 1017 Assert.fail("No exception raised"); 1018 } catch (InvalidArgumentException e) { 1019 // Expected exception. 1020 } 1021 } 1022 1023 @Test createNoteTest2()1024 public void createNoteTest2() throws Exception { 1025 Note expectedResponse = 1026 Note.newBuilder() 1027 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 1028 .setShortDescription("shortDescription1951089120") 1029 .setLongDescription("longDescription1763753952") 1030 .setKind(NoteKind.forNumber(0)) 1031 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 1032 .setExpirationTime(Timestamp.newBuilder().build()) 1033 .setCreateTime(Timestamp.newBuilder().build()) 1034 .setUpdateTime(Timestamp.newBuilder().build()) 1035 .addAllRelatedNoteNames(new ArrayList<String>()) 1036 .build(); 1037 mockGrafeas.addResponse(expectedResponse); 1038 1039 String parent = "parent-995424086"; 1040 String noteId = "noteId-1039694675"; 1041 Note note = Note.newBuilder().build(); 1042 1043 Note actualResponse = client.createNote(parent, noteId, note); 1044 Assert.assertEquals(expectedResponse, actualResponse); 1045 1046 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1047 Assert.assertEquals(1, actualRequests.size()); 1048 CreateNoteRequest actualRequest = ((CreateNoteRequest) actualRequests.get(0)); 1049 1050 Assert.assertEquals(parent, actualRequest.getParent()); 1051 Assert.assertEquals(noteId, actualRequest.getNoteId()); 1052 Assert.assertEquals(note, actualRequest.getNote()); 1053 Assert.assertTrue( 1054 channelProvider.isHeaderSent( 1055 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1056 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1057 } 1058 1059 @Test createNoteExceptionTest2()1060 public void createNoteExceptionTest2() throws Exception { 1061 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1062 mockGrafeas.addException(exception); 1063 1064 try { 1065 String parent = "parent-995424086"; 1066 String noteId = "noteId-1039694675"; 1067 Note note = Note.newBuilder().build(); 1068 client.createNote(parent, noteId, note); 1069 Assert.fail("No exception raised"); 1070 } catch (InvalidArgumentException e) { 1071 // Expected exception. 1072 } 1073 } 1074 1075 @Test batchCreateNotesTest()1076 public void batchCreateNotesTest() throws Exception { 1077 BatchCreateNotesResponse expectedResponse = 1078 BatchCreateNotesResponse.newBuilder().addAllNotes(new ArrayList<Note>()).build(); 1079 mockGrafeas.addResponse(expectedResponse); 1080 1081 ProjectName parent = ProjectName.of("[PROJECT]"); 1082 Map<String, Note> notes = new HashMap<>(); 1083 1084 BatchCreateNotesResponse actualResponse = client.batchCreateNotes(parent, notes); 1085 Assert.assertEquals(expectedResponse, actualResponse); 1086 1087 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1088 Assert.assertEquals(1, actualRequests.size()); 1089 BatchCreateNotesRequest actualRequest = ((BatchCreateNotesRequest) actualRequests.get(0)); 1090 1091 Assert.assertEquals(parent.toString(), actualRequest.getParent()); 1092 Assert.assertEquals(notes, actualRequest.getNotesMap()); 1093 Assert.assertTrue( 1094 channelProvider.isHeaderSent( 1095 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1096 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1097 } 1098 1099 @Test batchCreateNotesExceptionTest()1100 public void batchCreateNotesExceptionTest() throws Exception { 1101 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1102 mockGrafeas.addException(exception); 1103 1104 try { 1105 ProjectName parent = ProjectName.of("[PROJECT]"); 1106 Map<String, Note> notes = new HashMap<>(); 1107 client.batchCreateNotes(parent, notes); 1108 Assert.fail("No exception raised"); 1109 } catch (InvalidArgumentException e) { 1110 // Expected exception. 1111 } 1112 } 1113 1114 @Test batchCreateNotesTest2()1115 public void batchCreateNotesTest2() throws Exception { 1116 BatchCreateNotesResponse expectedResponse = 1117 BatchCreateNotesResponse.newBuilder().addAllNotes(new ArrayList<Note>()).build(); 1118 mockGrafeas.addResponse(expectedResponse); 1119 1120 String parent = "parent-995424086"; 1121 Map<String, Note> notes = new HashMap<>(); 1122 1123 BatchCreateNotesResponse actualResponse = client.batchCreateNotes(parent, notes); 1124 Assert.assertEquals(expectedResponse, actualResponse); 1125 1126 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1127 Assert.assertEquals(1, actualRequests.size()); 1128 BatchCreateNotesRequest actualRequest = ((BatchCreateNotesRequest) actualRequests.get(0)); 1129 1130 Assert.assertEquals(parent, actualRequest.getParent()); 1131 Assert.assertEquals(notes, actualRequest.getNotesMap()); 1132 Assert.assertTrue( 1133 channelProvider.isHeaderSent( 1134 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1135 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1136 } 1137 1138 @Test batchCreateNotesExceptionTest2()1139 public void batchCreateNotesExceptionTest2() throws Exception { 1140 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1141 mockGrafeas.addException(exception); 1142 1143 try { 1144 String parent = "parent-995424086"; 1145 Map<String, Note> notes = new HashMap<>(); 1146 client.batchCreateNotes(parent, notes); 1147 Assert.fail("No exception raised"); 1148 } catch (InvalidArgumentException e) { 1149 // Expected exception. 1150 } 1151 } 1152 1153 @Test updateNoteTest()1154 public void updateNoteTest() throws Exception { 1155 Note expectedResponse = 1156 Note.newBuilder() 1157 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 1158 .setShortDescription("shortDescription1951089120") 1159 .setLongDescription("longDescription1763753952") 1160 .setKind(NoteKind.forNumber(0)) 1161 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 1162 .setExpirationTime(Timestamp.newBuilder().build()) 1163 .setCreateTime(Timestamp.newBuilder().build()) 1164 .setUpdateTime(Timestamp.newBuilder().build()) 1165 .addAllRelatedNoteNames(new ArrayList<String>()) 1166 .build(); 1167 mockGrafeas.addResponse(expectedResponse); 1168 1169 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 1170 Note note = Note.newBuilder().build(); 1171 FieldMask updateMask = FieldMask.newBuilder().build(); 1172 1173 Note actualResponse = client.updateNote(name, note, updateMask); 1174 Assert.assertEquals(expectedResponse, actualResponse); 1175 1176 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1177 Assert.assertEquals(1, actualRequests.size()); 1178 UpdateNoteRequest actualRequest = ((UpdateNoteRequest) actualRequests.get(0)); 1179 1180 Assert.assertEquals(name.toString(), actualRequest.getName()); 1181 Assert.assertEquals(note, actualRequest.getNote()); 1182 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 1183 Assert.assertTrue( 1184 channelProvider.isHeaderSent( 1185 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1186 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1187 } 1188 1189 @Test updateNoteExceptionTest()1190 public void updateNoteExceptionTest() throws Exception { 1191 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1192 mockGrafeas.addException(exception); 1193 1194 try { 1195 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 1196 Note note = Note.newBuilder().build(); 1197 FieldMask updateMask = FieldMask.newBuilder().build(); 1198 client.updateNote(name, note, updateMask); 1199 Assert.fail("No exception raised"); 1200 } catch (InvalidArgumentException e) { 1201 // Expected exception. 1202 } 1203 } 1204 1205 @Test updateNoteTest2()1206 public void updateNoteTest2() throws Exception { 1207 Note expectedResponse = 1208 Note.newBuilder() 1209 .setName(NoteName.of("[PROJECT]", "[NOTE]").toString()) 1210 .setShortDescription("shortDescription1951089120") 1211 .setLongDescription("longDescription1763753952") 1212 .setKind(NoteKind.forNumber(0)) 1213 .addAllRelatedUrl(new ArrayList<RelatedUrl>()) 1214 .setExpirationTime(Timestamp.newBuilder().build()) 1215 .setCreateTime(Timestamp.newBuilder().build()) 1216 .setUpdateTime(Timestamp.newBuilder().build()) 1217 .addAllRelatedNoteNames(new ArrayList<String>()) 1218 .build(); 1219 mockGrafeas.addResponse(expectedResponse); 1220 1221 String name = "name3373707"; 1222 Note note = Note.newBuilder().build(); 1223 FieldMask updateMask = FieldMask.newBuilder().build(); 1224 1225 Note actualResponse = client.updateNote(name, note, updateMask); 1226 Assert.assertEquals(expectedResponse, actualResponse); 1227 1228 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1229 Assert.assertEquals(1, actualRequests.size()); 1230 UpdateNoteRequest actualRequest = ((UpdateNoteRequest) actualRequests.get(0)); 1231 1232 Assert.assertEquals(name, actualRequest.getName()); 1233 Assert.assertEquals(note, actualRequest.getNote()); 1234 Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); 1235 Assert.assertTrue( 1236 channelProvider.isHeaderSent( 1237 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1238 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1239 } 1240 1241 @Test updateNoteExceptionTest2()1242 public void updateNoteExceptionTest2() throws Exception { 1243 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1244 mockGrafeas.addException(exception); 1245 1246 try { 1247 String name = "name3373707"; 1248 Note note = Note.newBuilder().build(); 1249 FieldMask updateMask = FieldMask.newBuilder().build(); 1250 client.updateNote(name, note, updateMask); 1251 Assert.fail("No exception raised"); 1252 } catch (InvalidArgumentException e) { 1253 // Expected exception. 1254 } 1255 } 1256 1257 @Test listNoteOccurrencesTest()1258 public void listNoteOccurrencesTest() throws Exception { 1259 Occurrence responsesElement = Occurrence.newBuilder().build(); 1260 ListNoteOccurrencesResponse expectedResponse = 1261 ListNoteOccurrencesResponse.newBuilder() 1262 .setNextPageToken("") 1263 .addAllOccurrences(Arrays.asList(responsesElement)) 1264 .build(); 1265 mockGrafeas.addResponse(expectedResponse); 1266 1267 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 1268 String filter = "filter-1274492040"; 1269 1270 ListNoteOccurrencesPagedResponse pagedListResponse = client.listNoteOccurrences(name, filter); 1271 1272 List<Occurrence> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1273 1274 Assert.assertEquals(1, resources.size()); 1275 Assert.assertEquals(expectedResponse.getOccurrencesList().get(0), resources.get(0)); 1276 1277 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1278 Assert.assertEquals(1, actualRequests.size()); 1279 ListNoteOccurrencesRequest actualRequest = ((ListNoteOccurrencesRequest) actualRequests.get(0)); 1280 1281 Assert.assertEquals(name.toString(), actualRequest.getName()); 1282 Assert.assertEquals(filter, actualRequest.getFilter()); 1283 Assert.assertTrue( 1284 channelProvider.isHeaderSent( 1285 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1286 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1287 } 1288 1289 @Test listNoteOccurrencesExceptionTest()1290 public void listNoteOccurrencesExceptionTest() throws Exception { 1291 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1292 mockGrafeas.addException(exception); 1293 1294 try { 1295 NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); 1296 String filter = "filter-1274492040"; 1297 client.listNoteOccurrences(name, filter); 1298 Assert.fail("No exception raised"); 1299 } catch (InvalidArgumentException e) { 1300 // Expected exception. 1301 } 1302 } 1303 1304 @Test listNoteOccurrencesTest2()1305 public void listNoteOccurrencesTest2() throws Exception { 1306 Occurrence responsesElement = Occurrence.newBuilder().build(); 1307 ListNoteOccurrencesResponse expectedResponse = 1308 ListNoteOccurrencesResponse.newBuilder() 1309 .setNextPageToken("") 1310 .addAllOccurrences(Arrays.asList(responsesElement)) 1311 .build(); 1312 mockGrafeas.addResponse(expectedResponse); 1313 1314 String name = "name3373707"; 1315 String filter = "filter-1274492040"; 1316 1317 ListNoteOccurrencesPagedResponse pagedListResponse = client.listNoteOccurrences(name, filter); 1318 1319 List<Occurrence> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 1320 1321 Assert.assertEquals(1, resources.size()); 1322 Assert.assertEquals(expectedResponse.getOccurrencesList().get(0), resources.get(0)); 1323 1324 List<AbstractMessage> actualRequests = mockGrafeas.getRequests(); 1325 Assert.assertEquals(1, actualRequests.size()); 1326 ListNoteOccurrencesRequest actualRequest = ((ListNoteOccurrencesRequest) actualRequests.get(0)); 1327 1328 Assert.assertEquals(name, actualRequest.getName()); 1329 Assert.assertEquals(filter, actualRequest.getFilter()); 1330 Assert.assertTrue( 1331 channelProvider.isHeaderSent( 1332 ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), 1333 GaxGrpcProperties.getDefaultApiClientHeaderPattern())); 1334 } 1335 1336 @Test listNoteOccurrencesExceptionTest2()1337 public void listNoteOccurrencesExceptionTest2() throws Exception { 1338 StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); 1339 mockGrafeas.addException(exception); 1340 1341 try { 1342 String name = "name3373707"; 1343 String filter = "filter-1274492040"; 1344 client.listNoteOccurrences(name, filter); 1345 Assert.fail("No exception raised"); 1346 } catch (InvalidArgumentException e) { 1347 // Expected exception. 1348 } 1349 } 1350 } 1351