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.dialogflow.cx.v3; 18 19 import static com.google.cloud.dialogflow.cx.v3.PagesClient.ListLocationsPagedResponse; 20 import static com.google.cloud.dialogflow.cx.v3.PagesClient.ListPagesPagedResponse; 21 22 import com.google.api.gax.core.NoCredentialsProvider; 23 import com.google.api.gax.httpjson.GaxHttpJsonProperties; 24 import com.google.api.gax.httpjson.testing.MockHttpService; 25 import com.google.api.gax.rpc.ApiClientHeaderProvider; 26 import com.google.api.gax.rpc.ApiException; 27 import com.google.api.gax.rpc.ApiExceptionFactory; 28 import com.google.api.gax.rpc.InvalidArgumentException; 29 import com.google.api.gax.rpc.StatusCode; 30 import com.google.api.gax.rpc.testing.FakeStatusCode; 31 import com.google.cloud.dialogflow.cx.v3.stub.HttpJsonPagesStub; 32 import com.google.cloud.location.GetLocationRequest; 33 import com.google.cloud.location.ListLocationsRequest; 34 import com.google.cloud.location.ListLocationsResponse; 35 import com.google.cloud.location.Location; 36 import com.google.common.collect.Lists; 37 import com.google.protobuf.Any; 38 import com.google.protobuf.Empty; 39 import com.google.protobuf.FieldMask; 40 import java.io.IOException; 41 import java.util.ArrayList; 42 import java.util.Arrays; 43 import java.util.HashMap; 44 import java.util.List; 45 import javax.annotation.Generated; 46 import org.junit.After; 47 import org.junit.AfterClass; 48 import org.junit.Assert; 49 import org.junit.Before; 50 import org.junit.BeforeClass; 51 import org.junit.Test; 52 53 @Generated("by gapic-generator-java") 54 public class PagesClientHttpJsonTest { 55 private static MockHttpService mockService; 56 private static PagesClient client; 57 58 @BeforeClass startStaticServer()59 public static void startStaticServer() throws IOException { 60 mockService = 61 new MockHttpService( 62 HttpJsonPagesStub.getMethodDescriptors(), PagesSettings.getDefaultEndpoint()); 63 PagesSettings settings = 64 PagesSettings.newHttpJsonBuilder() 65 .setTransportChannelProvider( 66 PagesSettings.defaultHttpJsonTransportProviderBuilder() 67 .setHttpTransport(mockService) 68 .build()) 69 .setCredentialsProvider(NoCredentialsProvider.create()) 70 .build(); 71 client = PagesClient.create(settings); 72 } 73 74 @AfterClass stopServer()75 public static void stopServer() { 76 client.close(); 77 } 78 79 @Before setUp()80 public void setUp() {} 81 82 @After tearDown()83 public void tearDown() throws Exception { 84 mockService.reset(); 85 } 86 87 @Test listPagesTest()88 public void listPagesTest() throws Exception { 89 Page responsesElement = Page.newBuilder().build(); 90 ListPagesResponse expectedResponse = 91 ListPagesResponse.newBuilder() 92 .setNextPageToken("") 93 .addAllPages(Arrays.asList(responsesElement)) 94 .build(); 95 mockService.addResponse(expectedResponse); 96 97 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 98 99 ListPagesPagedResponse pagedListResponse = client.listPages(parent); 100 101 List<Page> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 102 103 Assert.assertEquals(1, resources.size()); 104 Assert.assertEquals(expectedResponse.getPagesList().get(0), resources.get(0)); 105 106 List<String> actualRequests = mockService.getRequestPaths(); 107 Assert.assertEquals(1, actualRequests.size()); 108 109 String apiClientHeaderKey = 110 mockService 111 .getRequestHeaders() 112 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 113 .iterator() 114 .next(); 115 Assert.assertTrue( 116 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 117 .matcher(apiClientHeaderKey) 118 .matches()); 119 } 120 121 @Test listPagesExceptionTest()122 public void listPagesExceptionTest() throws Exception { 123 ApiException exception = 124 ApiExceptionFactory.createException( 125 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 126 mockService.addException(exception); 127 128 try { 129 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 130 client.listPages(parent); 131 Assert.fail("No exception raised"); 132 } catch (InvalidArgumentException e) { 133 // Expected exception. 134 } 135 } 136 137 @Test listPagesTest2()138 public void listPagesTest2() throws Exception { 139 Page responsesElement = Page.newBuilder().build(); 140 ListPagesResponse expectedResponse = 141 ListPagesResponse.newBuilder() 142 .setNextPageToken("") 143 .addAllPages(Arrays.asList(responsesElement)) 144 .build(); 145 mockService.addResponse(expectedResponse); 146 147 String parent = 148 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 149 150 ListPagesPagedResponse pagedListResponse = client.listPages(parent); 151 152 List<Page> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 153 154 Assert.assertEquals(1, resources.size()); 155 Assert.assertEquals(expectedResponse.getPagesList().get(0), resources.get(0)); 156 157 List<String> actualRequests = mockService.getRequestPaths(); 158 Assert.assertEquals(1, actualRequests.size()); 159 160 String apiClientHeaderKey = 161 mockService 162 .getRequestHeaders() 163 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 164 .iterator() 165 .next(); 166 Assert.assertTrue( 167 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 168 .matcher(apiClientHeaderKey) 169 .matches()); 170 } 171 172 @Test listPagesExceptionTest2()173 public void listPagesExceptionTest2() throws Exception { 174 ApiException exception = 175 ApiExceptionFactory.createException( 176 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 177 mockService.addException(exception); 178 179 try { 180 String parent = 181 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 182 client.listPages(parent); 183 Assert.fail("No exception raised"); 184 } catch (InvalidArgumentException e) { 185 // Expected exception. 186 } 187 } 188 189 @Test getPageTest()190 public void getPageTest() throws Exception { 191 Page expectedResponse = 192 Page.newBuilder() 193 .setName( 194 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 195 .setDisplayName("displayName1714148973") 196 .setEntryFulfillment(Fulfillment.newBuilder().build()) 197 .setForm(Form.newBuilder().build()) 198 .addAllTransitionRouteGroups(new ArrayList<String>()) 199 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 200 .addAllEventHandlers(new ArrayList<EventHandler>()) 201 .build(); 202 mockService.addResponse(expectedResponse); 203 204 PageName name = PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]"); 205 206 Page actualResponse = client.getPage(name); 207 Assert.assertEquals(expectedResponse, actualResponse); 208 209 List<String> actualRequests = mockService.getRequestPaths(); 210 Assert.assertEquals(1, actualRequests.size()); 211 212 String apiClientHeaderKey = 213 mockService 214 .getRequestHeaders() 215 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 216 .iterator() 217 .next(); 218 Assert.assertTrue( 219 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 220 .matcher(apiClientHeaderKey) 221 .matches()); 222 } 223 224 @Test getPageExceptionTest()225 public void getPageExceptionTest() throws Exception { 226 ApiException exception = 227 ApiExceptionFactory.createException( 228 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 229 mockService.addException(exception); 230 231 try { 232 PageName name = PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]"); 233 client.getPage(name); 234 Assert.fail("No exception raised"); 235 } catch (InvalidArgumentException e) { 236 // Expected exception. 237 } 238 } 239 240 @Test getPageTest2()241 public void getPageTest2() throws Exception { 242 Page expectedResponse = 243 Page.newBuilder() 244 .setName( 245 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 246 .setDisplayName("displayName1714148973") 247 .setEntryFulfillment(Fulfillment.newBuilder().build()) 248 .setForm(Form.newBuilder().build()) 249 .addAllTransitionRouteGroups(new ArrayList<String>()) 250 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 251 .addAllEventHandlers(new ArrayList<EventHandler>()) 252 .build(); 253 mockService.addResponse(expectedResponse); 254 255 String name = 256 "projects/project-4063/locations/location-4063/agents/agent-4063/flows/flow-4063/pages/page-4063"; 257 258 Page actualResponse = client.getPage(name); 259 Assert.assertEquals(expectedResponse, actualResponse); 260 261 List<String> actualRequests = mockService.getRequestPaths(); 262 Assert.assertEquals(1, actualRequests.size()); 263 264 String apiClientHeaderKey = 265 mockService 266 .getRequestHeaders() 267 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 268 .iterator() 269 .next(); 270 Assert.assertTrue( 271 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 272 .matcher(apiClientHeaderKey) 273 .matches()); 274 } 275 276 @Test getPageExceptionTest2()277 public void getPageExceptionTest2() throws Exception { 278 ApiException exception = 279 ApiExceptionFactory.createException( 280 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 281 mockService.addException(exception); 282 283 try { 284 String name = 285 "projects/project-4063/locations/location-4063/agents/agent-4063/flows/flow-4063/pages/page-4063"; 286 client.getPage(name); 287 Assert.fail("No exception raised"); 288 } catch (InvalidArgumentException e) { 289 // Expected exception. 290 } 291 } 292 293 @Test createPageTest()294 public void createPageTest() throws Exception { 295 Page expectedResponse = 296 Page.newBuilder() 297 .setName( 298 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 299 .setDisplayName("displayName1714148973") 300 .setEntryFulfillment(Fulfillment.newBuilder().build()) 301 .setForm(Form.newBuilder().build()) 302 .addAllTransitionRouteGroups(new ArrayList<String>()) 303 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 304 .addAllEventHandlers(new ArrayList<EventHandler>()) 305 .build(); 306 mockService.addResponse(expectedResponse); 307 308 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 309 Page page = Page.newBuilder().build(); 310 311 Page actualResponse = client.createPage(parent, page); 312 Assert.assertEquals(expectedResponse, actualResponse); 313 314 List<String> actualRequests = mockService.getRequestPaths(); 315 Assert.assertEquals(1, actualRequests.size()); 316 317 String apiClientHeaderKey = 318 mockService 319 .getRequestHeaders() 320 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 321 .iterator() 322 .next(); 323 Assert.assertTrue( 324 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 325 .matcher(apiClientHeaderKey) 326 .matches()); 327 } 328 329 @Test createPageExceptionTest()330 public void createPageExceptionTest() throws Exception { 331 ApiException exception = 332 ApiExceptionFactory.createException( 333 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 334 mockService.addException(exception); 335 336 try { 337 FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]"); 338 Page page = Page.newBuilder().build(); 339 client.createPage(parent, page); 340 Assert.fail("No exception raised"); 341 } catch (InvalidArgumentException e) { 342 // Expected exception. 343 } 344 } 345 346 @Test createPageTest2()347 public void createPageTest2() throws Exception { 348 Page expectedResponse = 349 Page.newBuilder() 350 .setName( 351 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 352 .setDisplayName("displayName1714148973") 353 .setEntryFulfillment(Fulfillment.newBuilder().build()) 354 .setForm(Form.newBuilder().build()) 355 .addAllTransitionRouteGroups(new ArrayList<String>()) 356 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 357 .addAllEventHandlers(new ArrayList<EventHandler>()) 358 .build(); 359 mockService.addResponse(expectedResponse); 360 361 String parent = 362 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 363 Page page = Page.newBuilder().build(); 364 365 Page actualResponse = client.createPage(parent, page); 366 Assert.assertEquals(expectedResponse, actualResponse); 367 368 List<String> actualRequests = mockService.getRequestPaths(); 369 Assert.assertEquals(1, actualRequests.size()); 370 371 String apiClientHeaderKey = 372 mockService 373 .getRequestHeaders() 374 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 375 .iterator() 376 .next(); 377 Assert.assertTrue( 378 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 379 .matcher(apiClientHeaderKey) 380 .matches()); 381 } 382 383 @Test createPageExceptionTest2()384 public void createPageExceptionTest2() throws Exception { 385 ApiException exception = 386 ApiExceptionFactory.createException( 387 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 388 mockService.addException(exception); 389 390 try { 391 String parent = 392 "projects/project-7760/locations/location-7760/agents/agent-7760/flows/flow-7760"; 393 Page page = Page.newBuilder().build(); 394 client.createPage(parent, page); 395 Assert.fail("No exception raised"); 396 } catch (InvalidArgumentException e) { 397 // Expected exception. 398 } 399 } 400 401 @Test updatePageTest()402 public void updatePageTest() throws Exception { 403 Page expectedResponse = 404 Page.newBuilder() 405 .setName( 406 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 407 .setDisplayName("displayName1714148973") 408 .setEntryFulfillment(Fulfillment.newBuilder().build()) 409 .setForm(Form.newBuilder().build()) 410 .addAllTransitionRouteGroups(new ArrayList<String>()) 411 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 412 .addAllEventHandlers(new ArrayList<EventHandler>()) 413 .build(); 414 mockService.addResponse(expectedResponse); 415 416 Page page = 417 Page.newBuilder() 418 .setName( 419 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 420 .setDisplayName("displayName1714148973") 421 .setEntryFulfillment(Fulfillment.newBuilder().build()) 422 .setForm(Form.newBuilder().build()) 423 .addAllTransitionRouteGroups(new ArrayList<String>()) 424 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 425 .addAllEventHandlers(new ArrayList<EventHandler>()) 426 .build(); 427 FieldMask updateMask = FieldMask.newBuilder().build(); 428 429 Page actualResponse = client.updatePage(page, updateMask); 430 Assert.assertEquals(expectedResponse, actualResponse); 431 432 List<String> actualRequests = mockService.getRequestPaths(); 433 Assert.assertEquals(1, actualRequests.size()); 434 435 String apiClientHeaderKey = 436 mockService 437 .getRequestHeaders() 438 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 439 .iterator() 440 .next(); 441 Assert.assertTrue( 442 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 443 .matcher(apiClientHeaderKey) 444 .matches()); 445 } 446 447 @Test updatePageExceptionTest()448 public void updatePageExceptionTest() throws Exception { 449 ApiException exception = 450 ApiExceptionFactory.createException( 451 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 452 mockService.addException(exception); 453 454 try { 455 Page page = 456 Page.newBuilder() 457 .setName( 458 PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]").toString()) 459 .setDisplayName("displayName1714148973") 460 .setEntryFulfillment(Fulfillment.newBuilder().build()) 461 .setForm(Form.newBuilder().build()) 462 .addAllTransitionRouteGroups(new ArrayList<String>()) 463 .addAllTransitionRoutes(new ArrayList<TransitionRoute>()) 464 .addAllEventHandlers(new ArrayList<EventHandler>()) 465 .build(); 466 FieldMask updateMask = FieldMask.newBuilder().build(); 467 client.updatePage(page, updateMask); 468 Assert.fail("No exception raised"); 469 } catch (InvalidArgumentException e) { 470 // Expected exception. 471 } 472 } 473 474 @Test deletePageTest()475 public void deletePageTest() throws Exception { 476 Empty expectedResponse = Empty.newBuilder().build(); 477 mockService.addResponse(expectedResponse); 478 479 PageName name = PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]"); 480 481 client.deletePage(name); 482 483 List<String> actualRequests = mockService.getRequestPaths(); 484 Assert.assertEquals(1, actualRequests.size()); 485 486 String apiClientHeaderKey = 487 mockService 488 .getRequestHeaders() 489 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 490 .iterator() 491 .next(); 492 Assert.assertTrue( 493 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 494 .matcher(apiClientHeaderKey) 495 .matches()); 496 } 497 498 @Test deletePageExceptionTest()499 public void deletePageExceptionTest() throws Exception { 500 ApiException exception = 501 ApiExceptionFactory.createException( 502 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 503 mockService.addException(exception); 504 505 try { 506 PageName name = PageName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]", "[PAGE]"); 507 client.deletePage(name); 508 Assert.fail("No exception raised"); 509 } catch (InvalidArgumentException e) { 510 // Expected exception. 511 } 512 } 513 514 @Test deletePageTest2()515 public void deletePageTest2() throws Exception { 516 Empty expectedResponse = Empty.newBuilder().build(); 517 mockService.addResponse(expectedResponse); 518 519 String name = 520 "projects/project-4063/locations/location-4063/agents/agent-4063/flows/flow-4063/pages/page-4063"; 521 522 client.deletePage(name); 523 524 List<String> actualRequests = mockService.getRequestPaths(); 525 Assert.assertEquals(1, actualRequests.size()); 526 527 String apiClientHeaderKey = 528 mockService 529 .getRequestHeaders() 530 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 531 .iterator() 532 .next(); 533 Assert.assertTrue( 534 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 535 .matcher(apiClientHeaderKey) 536 .matches()); 537 } 538 539 @Test deletePageExceptionTest2()540 public void deletePageExceptionTest2() throws Exception { 541 ApiException exception = 542 ApiExceptionFactory.createException( 543 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 544 mockService.addException(exception); 545 546 try { 547 String name = 548 "projects/project-4063/locations/location-4063/agents/agent-4063/flows/flow-4063/pages/page-4063"; 549 client.deletePage(name); 550 Assert.fail("No exception raised"); 551 } catch (InvalidArgumentException e) { 552 // Expected exception. 553 } 554 } 555 556 @Test listLocationsTest()557 public void listLocationsTest() throws Exception { 558 Location responsesElement = Location.newBuilder().build(); 559 ListLocationsResponse expectedResponse = 560 ListLocationsResponse.newBuilder() 561 .setNextPageToken("") 562 .addAllLocations(Arrays.asList(responsesElement)) 563 .build(); 564 mockService.addResponse(expectedResponse); 565 566 ListLocationsRequest request = 567 ListLocationsRequest.newBuilder() 568 .setName("projects/project-3664") 569 .setFilter("filter-1274492040") 570 .setPageSize(883849137) 571 .setPageToken("pageToken873572522") 572 .build(); 573 574 ListLocationsPagedResponse pagedListResponse = client.listLocations(request); 575 576 List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll()); 577 578 Assert.assertEquals(1, resources.size()); 579 Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0)); 580 581 List<String> actualRequests = mockService.getRequestPaths(); 582 Assert.assertEquals(1, actualRequests.size()); 583 584 String apiClientHeaderKey = 585 mockService 586 .getRequestHeaders() 587 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 588 .iterator() 589 .next(); 590 Assert.assertTrue( 591 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 592 .matcher(apiClientHeaderKey) 593 .matches()); 594 } 595 596 @Test listLocationsExceptionTest()597 public void listLocationsExceptionTest() throws Exception { 598 ApiException exception = 599 ApiExceptionFactory.createException( 600 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 601 mockService.addException(exception); 602 603 try { 604 ListLocationsRequest request = 605 ListLocationsRequest.newBuilder() 606 .setName("projects/project-3664") 607 .setFilter("filter-1274492040") 608 .setPageSize(883849137) 609 .setPageToken("pageToken873572522") 610 .build(); 611 client.listLocations(request); 612 Assert.fail("No exception raised"); 613 } catch (InvalidArgumentException e) { 614 // Expected exception. 615 } 616 } 617 618 @Test getLocationTest()619 public void getLocationTest() throws Exception { 620 Location expectedResponse = 621 Location.newBuilder() 622 .setName("name3373707") 623 .setLocationId("locationId1541836720") 624 .setDisplayName("displayName1714148973") 625 .putAllLabels(new HashMap<String, String>()) 626 .setMetadata(Any.newBuilder().build()) 627 .build(); 628 mockService.addResponse(expectedResponse); 629 630 GetLocationRequest request = 631 GetLocationRequest.newBuilder() 632 .setName("projects/project-9062/locations/location-9062") 633 .build(); 634 635 Location actualResponse = client.getLocation(request); 636 Assert.assertEquals(expectedResponse, actualResponse); 637 638 List<String> actualRequests = mockService.getRequestPaths(); 639 Assert.assertEquals(1, actualRequests.size()); 640 641 String apiClientHeaderKey = 642 mockService 643 .getRequestHeaders() 644 .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) 645 .iterator() 646 .next(); 647 Assert.assertTrue( 648 GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() 649 .matcher(apiClientHeaderKey) 650 .matches()); 651 } 652 653 @Test getLocationExceptionTest()654 public void getLocationExceptionTest() throws Exception { 655 ApiException exception = 656 ApiExceptionFactory.createException( 657 new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); 658 mockService.addException(exception); 659 660 try { 661 GetLocationRequest request = 662 GetLocationRequest.newBuilder() 663 .setName("projects/project-9062/locations/location-9062") 664 .build(); 665 client.getLocation(request); 666 Assert.fail("No exception raised"); 667 } catch (InvalidArgumentException e) { 668 // Expected exception. 669 } 670 } 671 } 672