Skip to content

Commit

Permalink
fix: Fallback to default value of maxRetryAttempts when restoring `…
Browse files Browse the repository at this point in the history
…BoxAPIConnection` (#1161)

Closes: SDK-3109
Fixes: #1160
  • Loading branch information
lukaszsocha2 authored Apr 21, 2023
1 parent d85e755 commit 2a10e5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/box/sdk/BoxAPIConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ public void restore(String state) {
// Try to use deprecated value "maxRequestAttempts", else use newer value "maxRetryAttempts"
if (maxRequestAttempts > -1) {
this.maxRetryAttempts = maxRequestAttempts - 1;
} else {
}
if (maxRetryAttempts > -1) {
this.maxRetryAttempts = maxRetryAttempts;
}

Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/box/sdk/BoxAPIConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,31 @@ public void restoresProperUrlsWhenSomeAreMissing() {
assertThat("https://upload.box.com/api/2.0/", is(restoredApi.getBaseUploadURL()));
}

@Test
public void restoresDefaultMaxRequestAttemptsWhenMissing() {
// given
String accessToken = "access_token";
String clientId = "some_client_id";
String clientSecret = "some_client_secret";
String refreshToken = "some_refresh_token";

String savedConnection = "{"
+ "\"accessToken\":\"access_token\","
+ "\"refreshToken\":\"some_refresh_token\","
+ "\"lastRefresh\":0,"
+ "\"expires\":0,"
+ "\"userAgent\":\"Box Java SDK v3.8.0 (Java 1.8.0_345)\","
+ "\"baseURL\":\"https://api.box.com/\","
+ "\"authorizationURL\":\"https://account.box.com/api/\","
+ "\"autoRefresh\":true"
+ "}";
// when
BoxAPIConnection restoredApi = BoxAPIConnection.restore(clientId, clientSecret, savedConnection);

// then
assertThat(BoxGlobalSettings.getMaxRetryAttempts(), is(restoredApi.getMaxRetryAttempts()));
}

@Test
public void successfullyRestoresConnectionWithDeprecatedSettings() {
String restoreState = TestUtils.getFixture("BoxAPIConnection/State");
Expand Down

0 comments on commit 2a10e5d

Please sign in to comment.