|
23 | 23 | import com.eclipsesource.json.JsonObject; |
24 | 24 | import com.github.tomakehurst.wiremock.client.WireMock; |
25 | 25 | import com.github.tomakehurst.wiremock.junit.WireMockRule; |
26 | | -import java.io.IOException; |
27 | 26 | import java.net.MalformedURLException; |
28 | 27 | import java.net.URI; |
29 | 28 | import java.net.URISyntaxException; |
@@ -499,7 +498,99 @@ public void allowsToSaveAndRestoreApplicationConnection() throws URISyntaxExcept |
499 | 498 | } |
500 | 499 |
|
501 | 500 | @Test |
502 | | - public void successfullyRestoresConnectionWithDeprecatedSettings() throws IOException { |
| 501 | + public void restoresProperUrlsFromOldVersions() { |
| 502 | + // given |
| 503 | + String accessToken = "access_token"; |
| 504 | + String clientId = "some_client_id"; |
| 505 | + String clientSecret = "some_client_secret"; |
| 506 | + String refreshToken = "some_refresh_token"; |
| 507 | + BoxAPIConnection api = new BoxAPIConnection(clientId, clientSecret, accessToken, refreshToken); |
| 508 | + api.setBaseURL("https://api.box.com/2.0/"); |
| 509 | + api.setBaseUploadURL("https://upload.box.com/api/2.0/"); |
| 510 | + String savedConnection = api.save(); |
| 511 | + |
| 512 | + // when |
| 513 | + BoxAPIConnection restoredApi = BoxAPIConnection.restore(clientId, clientSecret, savedConnection); |
| 514 | + |
| 515 | + // then |
| 516 | + assertThat("https://api.box.com/2.0/", is(restoredApi.getBaseURL())); |
| 517 | + assertThat("https://upload.box.com/api/2.0/", is(restoredApi.getBaseUploadURL())); |
| 518 | + } |
| 519 | + |
| 520 | + @Test |
| 521 | + public void restoresProperUrlsWhenNotSet() { |
| 522 | + // given |
| 523 | + String accessToken = "access_token"; |
| 524 | + String clientId = "some_client_id"; |
| 525 | + String clientSecret = "some_client_secret"; |
| 526 | + String refreshToken = "some_refresh_token"; |
| 527 | + BoxAPIConnection api = new BoxAPIConnection(clientId, clientSecret, accessToken, refreshToken); |
| 528 | + api.setBaseURL("https://api.box.com/2.0/"); |
| 529 | + String savedConnection = api.save(); |
| 530 | + |
| 531 | + // when |
| 532 | + BoxAPIConnection restoredApi = BoxAPIConnection.restore(clientId, clientSecret, savedConnection); |
| 533 | + |
| 534 | + // then |
| 535 | + assertThat("https://api.box.com/2.0/", is(restoredApi.getBaseURL())); |
| 536 | + assertThat("https://upload.box.com/api/2.0/", is(restoredApi.getBaseUploadURL())); |
| 537 | + } |
| 538 | + |
| 539 | + @Test |
| 540 | + public void restoresProperUrlsWhenDeprecatedUrlsAreSet() { |
| 541 | + // given |
| 542 | + String clientId = "some_client_id"; |
| 543 | + String clientSecret = "some_client_secret"; |
| 544 | + |
| 545 | + String savedConnection = "{" |
| 546 | + + "\"accessToken\":\"access_token\"," |
| 547 | + + "\"refreshToken\":\"some_refresh_token\"," |
| 548 | + + "\"lastRefresh\":0," |
| 549 | + + "\"expires\":0," |
| 550 | + + "\"userAgent\":\"Box Java SDK v3.8.0 (Java 1.8.0_345)\"," |
| 551 | + + "\"tokenURL\":\"https://api.box.com/token\"," |
| 552 | + + "\"revokeURL\":\"https://api.box.com/revoke\"," |
| 553 | + + "\"baseURL\":\"https://api.box.com/\"," |
| 554 | + + "\"baseUploadURL\":\"https://upload.box.com/api/\"," |
| 555 | + + "\"authorizationURL\":\"https://account.box.com/api/\"," |
| 556 | + + "\"autoRefresh\":true,\"maxRetryAttempts\":5" |
| 557 | + + "}"; |
| 558 | + // when |
| 559 | + BoxAPIConnection restoredApi = BoxAPIConnection.restore(clientId, clientSecret, savedConnection); |
| 560 | + |
| 561 | + // then |
| 562 | + assertThat("https://api.box.com/token", is(restoredApi.getTokenURL())); |
| 563 | + assertThat("https://api.box.com/revoke", is(restoredApi.getRevokeURL())); |
| 564 | + } |
| 565 | + |
| 566 | + @Test |
| 567 | + public void restoresProperUrlsWhenSomeAreMissing() { |
| 568 | + // given |
| 569 | + String accessToken = "access_token"; |
| 570 | + String clientId = "some_client_id"; |
| 571 | + String clientSecret = "some_client_secret"; |
| 572 | + String refreshToken = "some_refresh_token"; |
| 573 | + |
| 574 | + String savedConnection = "{" |
| 575 | + + "\"accessToken\":\"access_token\"," |
| 576 | + + "\"refreshToken\":\"some_refresh_token\"," |
| 577 | + + "\"lastRefresh\":0," |
| 578 | + + "\"expires\":0," |
| 579 | + + "\"userAgent\":\"Box Java SDK v3.8.0 (Java 1.8.0_345)\"," |
| 580 | + + "\"baseURL\":\"https://api.box.com/\"," |
| 581 | + + "\"authorizationURL\":\"https://account.box.com/api/\"," |
| 582 | + + "\"autoRefresh\":true,\"maxRetryAttempts\":5" |
| 583 | + + "}"; |
| 584 | + // when |
| 585 | + BoxAPIConnection restoredApi = BoxAPIConnection.restore(clientId, clientSecret, savedConnection); |
| 586 | + |
| 587 | + // then |
| 588 | + assertThat("https://api.box.com/2.0/", is(restoredApi.getBaseURL())); |
| 589 | + assertThat("https://upload.box.com/api/2.0/", is(restoredApi.getBaseUploadURL())); |
| 590 | + } |
| 591 | + |
| 592 | + @Test |
| 593 | + public void successfullyRestoresConnectionWithDeprecatedSettings() { |
503 | 594 | String restoreState = TestUtils.getFixture("BoxAPIConnection/State"); |
504 | 595 | String restoreStateDeprecated = TestUtils.getFixture("BoxAPIConnection/StateDeprecated"); |
505 | 596 |
|
|
0 commit comments