From 135850d97164ee5f6d74708d74c531f7fa8bee26 Mon Sep 17 00:00:00 2001 From: Kamil Berdychowski Date: Tue, 20 Sep 2022 14:33:48 +0200 Subject: [PATCH] fix: `BoxCollaboration.getItem()` returns `BoxItem.Info` not `BoxFolder.Info` (#1102) * fix: BoxCollaboration.getItem() should return BoxItem.Info not BoxFolder.Info Fixes #1101 * fix: Added details on retrying failed requests. Fixes #1100 --- doc/configuration.md | 12 +- doc/users.md | 6 +- src/intTest/java/com/box/sdk/BoxUserIT.java | 25 ++- .../java/com/box/sdk/BoxCollaboration.java | 168 ++++++++++-------- src/main/java/com/box/sdk/BoxFile.java | 58 +++--- src/main/java/com/box/sdk/BoxFolder.java | 53 +++--- src/main/java/com/box/sdk/BoxUser.java | 157 ++++++++++------ .../com/box/sdk/BoxCollaborationTest.java | 36 ++-- src/test/java/com/box/sdk/BoxFileTest.java | 63 ++++--- src/test/java/com/box/sdk/BoxFolderTest.java | 79 ++++---- src/test/java/com/box/sdk/BoxUserTest.java | 18 +- src/test/java/com/box/sdk/TestUtils.java | 4 +- 12 files changed, 418 insertions(+), 261 deletions(-) diff --git a/doc/configuration.md b/doc/configuration.md index c6e65a72a..cc80b5eca 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -31,6 +31,16 @@ api.setProxyPassword("proxyPassword"); ``` # Configure retries of calls and timeouts +SDK can retry failed calls when: + - failed writting request body + - when recieved HTTP response code: + - 429 - rate limit exceeded + - 5XX - internal server error + - 400 error with error that `exp` claim has expired. This usially means there is a clock skew. + +SDK is using exponnetial strategy to calculate time between retries. + If response contains `Retry-After` header its value will be used as a wait time between calls. +You can check details in `com.box.sdk.BoxAPIRequest.send(com.box.sdk.ProgressListener)` method. ## Maximum retries @@ -140,4 +150,4 @@ BoxAPIConnection api = new BoxAPIConnection("YOUR-DEVELOPER-TOKEN"); api.setRevokeURL("https://example.com/revoke"); ``` -If you use `setRevokeUrl` this URL will be used over the one coming from`setBaseUrl` when doing authentication. \ No newline at end of file +If you use `setRevokeUrl` this URL will be used over the one coming from`setBaseUrl` when doing authentication. diff --git a/doc/users.md b/doc/users.md index b055637e8..fc808a8b5 100644 --- a/doc/users.md +++ b/doc/users.md @@ -159,7 +159,8 @@ user.updateInfo(info); ## Delete User -To delete a user call the [`delete(boolean notifyUser, boolean force)`][delete] method. +To delete a user call the [`delete(boolean notifyUser, boolean force)`][deleteWithParams] method or one that +uses API default parameters [`delete()][delete] The `notifyUser` determines whether the user should receive an email about the deletion, and the `force` parameter will cause the user to be deleted even if they still have files @@ -171,7 +172,8 @@ BoxUser user = new BoxUser(api, "0"); user.delete(false, false); ``` -[delete]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxUser.html#delete-boolean-boolean- +[deleteWithParams]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxUser.html#delete-boolean-boolean- +[delete]: https://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxUser.html#delete-- ## Invite User diff --git a/src/intTest/java/com/box/sdk/BoxUserIT.java b/src/intTest/java/com/box/sdk/BoxUserIT.java index 058601723..a22f4019f 100644 --- a/src/intTest/java/com/box/sdk/BoxUserIT.java +++ b/src/intTest/java/com/box/sdk/BoxUserIT.java @@ -54,7 +54,7 @@ public void getCurrentUserInfoIsCorrect() { } @Test(timeout = 10000) - public void createAndDeleteEnterpriseUserSucceeds() { + public void createAndForcefullyDeleteEnterpriseUser() { BoxAPIConnection api = jwtApiForServiceAccount(); // Since deleting users happens in a separate process in the backend // it is really an asynchronous call. So we have to use a new user in @@ -66,7 +66,26 @@ public void createAndDeleteEnterpriseUserSucceeds() { assertEquals(NEW_USER_NAME, createdUserInfo.getName()); assertEquals(NEW_USER_LOGIN, createdUserInfo.getLogin()); - createdUserInfo.getResource().delete(false, false); + createdUserInfo.getResource().delete(false, true); + + Iterable users = BoxUser.getAllEnterpriseUsers(api, NEW_USER_LOGIN); + assertThat(createListFrom(users), Matchers.hasSize(0)); + } + + @Test(timeout = 10000) + public void createAndDeleteEnterpriseUser() { + BoxAPIConnection api = jwtApiForServiceAccount(); + // Since deleting users happens in a separate process in the backend + // it is really an asynchronous call. So we have to use a new user in + // this test in case the previous user's deletion hasn't completed. + + BoxUser.Info createdUserInfo = BoxUser.createEnterpriseUser(api, NEW_USER_LOGIN, NEW_USER_NAME); + + assertNotNull(createdUserInfo.getID()); + assertEquals(NEW_USER_NAME, createdUserInfo.getName()); + assertEquals(NEW_USER_LOGIN, createdUserInfo.getLogin()); + + createdUserInfo.getResource().delete(); Iterable users = BoxUser.getAllEnterpriseUsers(api, NEW_USER_LOGIN); assertThat(createListFrom(users), Matchers.hasSize(0)); @@ -92,7 +111,7 @@ public void getMembershipsHasCorrectMemberships() { } @Test(timeout = 10000) - public void updateInfoSucceeds() { + public void updateUserInfo() { BoxAPIConnection api = jwtApiForServiceAccount(); final String login = "login3+" + Calendar.getInstance().getTimeInMillis() + "@boz.com"; final String originalName = "original name"; diff --git a/src/main/java/com/box/sdk/BoxCollaboration.java b/src/main/java/com/box/sdk/BoxCollaboration.java index c5d8f8afa..47cf24961 100644 --- a/src/main/java/com/box/sdk/BoxCollaboration.java +++ b/src/main/java/com/box/sdk/BoxCollaboration.java @@ -331,24 +331,25 @@ public enum Role { } static Role fromJSONString(String jsonValue) { - if (jsonValue.equals("editor")) { - return EDITOR; - } else if (jsonValue.equals("viewer")) { - return VIEWER; - } else if (jsonValue.equals("previewer")) { - return PREVIEWER; - } else if (jsonValue.equals("uploader")) { - return UPLOADER; - } else if (jsonValue.equals("previewer uploader")) { - return PREVIEWER_UPLOADER; - } else if (jsonValue.equals("viewer uploader")) { - return VIEWER_UPLOADER; - } else if (jsonValue.equals("co-owner")) { - return CO_OWNER; - } else if (jsonValue.equals("owner")) { - return OWNER; - } else { - throw new IllegalArgumentException("The provided JSON value isn't a valid Role."); + switch (jsonValue) { + case "editor": + return EDITOR; + case "viewer": + return VIEWER; + case "previewer": + return PREVIEWER; + case "uploader": + return UPLOADER; + case "previewer uploader": + return PREVIEWER_UPLOADER; + case "viewer uploader": + return VIEWER_UPLOADER; + case "co-owner": + return CO_OWNER; + case "owner": + return OWNER; + default: + throw new IllegalArgumentException("The provided JSON value isn't a valid Role."); } } @@ -360,7 +361,7 @@ String toJSONString() { /** * Contains information about a BoxCollaboration. */ - public class Info extends BoxResource.Info { + public class Info extends BoxResource.Info { private BoxUser.Info createdBy; private Date createdAt; private Date modifiedAt; @@ -369,8 +370,7 @@ public class Info extends BoxResource.Info { private BoxCollaborator.Info accessibleBy; private Role role; private Date acknowledgedAt; - private BoxFolder.Info item; - private BoxFile.Info fileItem; + private BoxItem.Info item; private String inviteEmail; private boolean canViewPath; @@ -532,7 +532,7 @@ public Date getAcknowledgedAt() { * * @return the folder the collaboration is related to. */ - public BoxFolder.Info getItem() { + public BoxItem.Info getItem() { return this.item; } @@ -541,6 +541,7 @@ public BoxCollaboration getResource() { return BoxCollaboration.this; } + @SuppressWarnings("checkstyle:MissingSwitchDefault") @Override protected void parseJSONMember(JsonObject.Member member) { super.parseJSONMember(member); @@ -548,63 +549,84 @@ protected void parseJSONMember(JsonObject.Member member) { String memberName = member.getName(); JsonValue value = member.getValue(); try { - if (memberName.equals("created_by")) { - JsonObject userJSON = value.asObject(); - if (this.createdBy == null) { - String userID = userJSON.get("id").asString(); - BoxUser user = new BoxUser(getAPI(), userID); - this.createdBy = user.new Info(userJSON); - } else { - this.createdBy.update(userJSON); - } - - } else if (memberName.equals("created_at")) { - this.createdAt = BoxDateFormat.parse(value.asString()); - - } else if (memberName.equals("modified_at")) { - this.modifiedAt = BoxDateFormat.parse(value.asString()); - - } else if (memberName.equals("expires_at")) { - this.expiresAt = BoxDateFormat.parse(value.asString()); - - } else if (memberName.equals("status")) { - String statusString = value.asString().toUpperCase(); - this.status = Status.valueOf(statusString); - - } else if (memberName.equals("accessible_by")) { - JsonObject accessibleByJSON = value.asObject(); - if (this.accessibleBy == null) { - this.accessibleBy = this.parseAccessibleBy(accessibleByJSON); - } else { - this.updateAccessibleBy(accessibleByJSON); - } - } else if (memberName.equals("role")) { - this.role = Role.fromJSONString(value.asString()); - - } else if (memberName.equals("acknowledged_at")) { - this.acknowledgedAt = BoxDateFormat.parse(value.asString()); - - } else if (memberName.equals("can_view_path")) { - this.canViewPath = value.asBoolean(); - - } else if (memberName.equals("invite_email")) { - this.inviteEmail = value.asString(); - - } else if (memberName.equals("item")) { - JsonObject folderJSON = value.asObject(); - if (this.item == null) { - String folderID = folderJSON.get("id").asString(); - BoxFolder folder = new BoxFolder(getAPI(), folderID); - this.item = folder.new Info(folderJSON); - } else { - this.item.update(folderJSON); - } + switch (memberName) { + case "created_by": + JsonObject userJSON = value.asObject(); + if (this.createdBy == null) { + String userID = userJSON.get("id").asString(); + BoxUser user = new BoxUser(getAPI(), userID); + this.createdBy = user.new Info(userJSON); + } else { + this.createdBy.update(userJSON); + } + break; + case "created_at": + this.createdAt = BoxDateFormat.parse(value.asString()); + + break; + case "modified_at": + this.modifiedAt = BoxDateFormat.parse(value.asString()); + break; + case "expires_at": + this.expiresAt = BoxDateFormat.parse(value.asString()); + break; + case "status": + String statusString = value.asString().toUpperCase(); + this.status = Status.valueOf(statusString); + + break; + case "accessible_by": + JsonObject accessibleByJSON = value.asObject(); + if (this.accessibleBy == null) { + this.accessibleBy = this.parseAccessibleBy(accessibleByJSON); + } else { + this.updateAccessibleBy(accessibleByJSON); + } + break; + case "role": + this.role = Role.fromJSONString(value.asString()); + break; + case "acknowledged_at": + this.acknowledgedAt = BoxDateFormat.parse(value.asString()); + break; + case "can_view_path": + this.canViewPath = value.asBoolean(); + break; + case "invite_email": + this.inviteEmail = value.asString(); + break; + case "item": + JsonObject itemJson = value.asObject(); + if (this.item == null) { + this.item = selectCollaborationItem(itemJson); + } else { + this.item.update(itemJson); + } + break; } } catch (Exception e) { throw new BoxDeserializationException(memberName, value.toString(), e); } } + private BoxItem.Info selectCollaborationItem(JsonObject itemJson) { + String itemId = itemJson.get("id").asString(); + String itemType = itemJson.get("type").asString(); + switch (itemType) { + case BoxFile.TYPE: + return new BoxFile(getAPI(), itemId).new Info(itemJson); + case BoxFolder.TYPE: + return new BoxFolder(getAPI(), itemId).new Info(itemJson); + default: + throw new IllegalStateException( + String.format( + "Unsupported collaboration item type '%s': JSON %n%s", + itemType, + itemJson + )); + } + } + private void updateAccessibleBy(JsonObject json) { String type = json.get("type").asString(); if ((type.equals("user") && this.accessibleBy instanceof BoxUser.Info) diff --git a/src/main/java/com/box/sdk/BoxFile.java b/src/main/java/com/box/sdk/BoxFile.java index 9dffaf58d..a457af826 100644 --- a/src/main/java/com/box/sdk/BoxFile.java +++ b/src/main/java/com/box/sdk/BoxFile.java @@ -122,6 +122,10 @@ public class BoxFile extends BoxItem { * Get All File Collaborations URL Template. */ public static final URLTemplate GET_ALL_FILE_COLLABORATIONS_URL = new URLTemplate("files/%s/collaborations"); + /** + * Describes file item type. + */ + static final String TYPE = "file"; private static final int BUFFER_SIZE = 8192; private static final int GET_COLLABORATORS_PAGE_SIZE = 1000; @@ -1756,7 +1760,6 @@ public class Info extends BoxItem.Info { private BoxLock lock; private boolean isWatermarked; private boolean isExternallyOwned; - private JsonObject metadata; private Map> metadataMap; private List representations; private List allowedInviteeRoles; @@ -1991,7 +1994,6 @@ protected void parseJSONMember(JsonObject.Member member) { String memberName = member.getName(); JsonValue value = member.getValue(); - JsonObject jsonObject; try { switch (memberName) { case "sha1": @@ -2040,16 +2042,13 @@ protected void parseJSONMember(JsonObject.Member member) { } break; case "watermark_info": - jsonObject = value.asObject(); - this.isWatermarked = jsonObject.get("is_watermarked").asBoolean(); + this.isWatermarked = value.asObject().get("is_watermarked").asBoolean(); break; case "metadata": - jsonObject = value.asObject(); - this.metadataMap = Parsers.parseAndPopulateMetadataMap(jsonObject); + this.metadataMap = Parsers.parseAndPopulateMetadataMap(value.asObject()); break; case "representations": - jsonObject = value.asObject(); - this.representations = Parsers.parseRepresentations(jsonObject); + this.representations = Parsers.parseRepresentations(value.asObject()); break; case "uploader_display_name": this.uploaderDisplayName = value.asString(); @@ -2075,6 +2074,7 @@ protected void parseJSONMember(JsonObject.Member member) { } } + @SuppressWarnings("checkstyle:MissingSwitchDefault") private EnumSet parsePermissions(JsonObject jsonObject) { EnumSet permissions = EnumSet.noneOf(Permission.class); for (JsonObject.Member member : jsonObject) { @@ -2083,23 +2083,31 @@ private EnumSet parsePermissions(JsonObject jsonObject) { continue; } - String memberName = member.getName(); - if (memberName.equals("can_download")) { - permissions.add(Permission.CAN_DOWNLOAD); - } else if (memberName.equals("can_upload")) { - permissions.add(Permission.CAN_UPLOAD); - } else if (memberName.equals("can_rename")) { - permissions.add(Permission.CAN_RENAME); - } else if (memberName.equals("can_delete")) { - permissions.add(Permission.CAN_DELETE); - } else if (memberName.equals("can_share")) { - permissions.add(Permission.CAN_SHARE); - } else if (memberName.equals("can_set_share_access")) { - permissions.add(Permission.CAN_SET_SHARE_ACCESS); - } else if (memberName.equals("can_preview")) { - permissions.add(Permission.CAN_PREVIEW); - } else if (memberName.equals("can_comment")) { - permissions.add(Permission.CAN_COMMENT); + switch (member.getName()) { + case "can_download": + permissions.add(Permission.CAN_DOWNLOAD); + break; + case "can_upload": + permissions.add(Permission.CAN_UPLOAD); + break; + case "can_rename": + permissions.add(Permission.CAN_RENAME); + break; + case "can_delete": + permissions.add(Permission.CAN_DELETE); + break; + case "can_share": + permissions.add(Permission.CAN_SHARE); + break; + case "can_set_share_access": + permissions.add(Permission.CAN_SET_SHARE_ACCESS); + break; + case "can_preview": + permissions.add(Permission.CAN_PREVIEW); + break; + case "can_comment": + permissions.add(Permission.CAN_COMMENT); + break; } } diff --git a/src/main/java/com/box/sdk/BoxFolder.java b/src/main/java/com/box/sdk/BoxFolder.java index 3b26ba3f4..849ec5d67 100644 --- a/src/main/java/com/box/sdk/BoxFolder.java +++ b/src/main/java/com/box/sdk/BoxFolder.java @@ -95,6 +95,10 @@ public class BoxFolder extends BoxItem implements Iterable { * Folder Locks URL Template. */ public static final URLTemplate FOLDER_LOCK_URL_TEMPLATE = new URLTemplate("folder_locks"); + /** + * Describes folder item type. + */ + static final String TYPE = "folder"; /** * Constructs a BoxFolder for a folder with a given ID. @@ -1672,7 +1676,6 @@ protected void parseJSONMember(JsonObject.Member member) { String memberName = member.getName(); JsonValue value = member.getValue(); - JsonObject jsonObject; try { switch (memberName) { case "folder_upload_email": @@ -1684,15 +1687,12 @@ protected void parseJSONMember(JsonObject.Member member) { break; case "has_collaborations": this.hasCollaborations = value.asBoolean(); - break; case "sync_state": this.syncState = SyncState.fromJSONValue(value.asString()); - break; case "permissions": this.permissions = this.parsePermissions(value.asObject()); - break; case "can_non_owners_invite": this.canNonOwnersInvite = value.asBoolean(); @@ -1710,12 +1710,10 @@ protected void parseJSONMember(JsonObject.Member member) { this.isExternallyOwned = value.asBoolean(); break; case "watermark_info": - jsonObject = value.asObject(); - this.isWatermarked = jsonObject.get("is_watermarked").asBoolean(); + this.isWatermarked = value.asObject().get("is_watermarked").asBoolean(); break; case "metadata": - jsonObject = value.asObject(); - this.metadataMap = Parsers.parseAndPopulateMetadataMap(jsonObject); + this.metadataMap = Parsers.parseAndPopulateMetadataMap(value.asObject()); break; case "classification": if (value.isNull()) { @@ -1743,21 +1741,30 @@ private EnumSet parsePermissions(JsonObject jsonObject) { continue; } - String memberName = member.getName(); - if (memberName.equals("can_download")) { - permissions.add(Permission.CAN_DOWNLOAD); - } else if (memberName.equals("can_upload")) { - permissions.add(Permission.CAN_UPLOAD); - } else if (memberName.equals("can_rename")) { - permissions.add(Permission.CAN_RENAME); - } else if (memberName.equals("can_delete")) { - permissions.add(Permission.CAN_DELETE); - } else if (memberName.equals("can_share")) { - permissions.add(Permission.CAN_SHARE); - } else if (memberName.equals("can_invite_collaborator")) { - permissions.add(Permission.CAN_INVITE_COLLABORATOR); - } else if (memberName.equals("can_set_share_access")) { - permissions.add(Permission.CAN_SET_SHARE_ACCESS); + switch (member.getName()) { + case "can_download": + permissions.add(Permission.CAN_DOWNLOAD); + break; + case "can_upload": + permissions.add(Permission.CAN_UPLOAD); + break; + case "can_rename": + permissions.add(Permission.CAN_RENAME); + break; + case "can_delete": + permissions.add(Permission.CAN_DELETE); + break; + case "can_share": + permissions.add(Permission.CAN_SHARE); + break; + case "can_invite_collaborator": + permissions.add(Permission.CAN_INVITE_COLLABORATOR); + break; + case "can_set_share_access": + permissions.add(Permission.CAN_SET_SHARE_ACCESS); + break; + default: + break; } } diff --git a/src/main/java/com/box/sdk/BoxUser.java b/src/main/java/com/box/sdk/BoxUser.java index 9a8ab515e..95978c149 100644 --- a/src/main/java/com/box/sdk/BoxUser.java +++ b/src/main/java/com/box/sdk/BoxUser.java @@ -586,6 +586,18 @@ public void delete(boolean notifyUser, boolean force) { .appendParam("force", String.valueOf(force)) .toString(); + performUserDelete(queryString); + } + + /** + * Deletes a user from an enterprise account. Uses API default values to determine if request should + * be forced and if user should be notified. + */ + public void delete() { + performUserDelete(""); + } + + private void performUserDelete(String queryString) { URL url = USER_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID()); BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "DELETE"); BoxAPIResponse response = request.send(); @@ -1315,6 +1327,7 @@ public void appendTrackingCodes(String name, String value) { this.addPendingChange("tracking_codes", toTrackingCodesJson(this.trackingCodes)); } + @SuppressWarnings("checkstyle:MissingSwitchDefault") @Override protected void parseJSONMember(JsonObject.Member member) { super.parseJSONMember(member); @@ -1322,65 +1335,91 @@ protected void parseJSONMember(JsonObject.Member member) { JsonValue value = member.getValue(); String memberName = member.getName(); try { - if (memberName.equals("login")) { - this.login = value.asString(); - } else if (memberName.equals("role")) { - this.role = Role.fromJSONValue(value.asString()); - } else if (memberName.equals("language")) { - this.language = value.asString(); - } else if (memberName.equals("timezone")) { - this.timezone = value.asString(); - } else if (memberName.equals("space_amount")) { - this.spaceAmount = Double.valueOf(value.toString()).longValue(); - } else if (memberName.equals("space_used")) { - this.spaceUsed = Double.valueOf(value.toString()).longValue(); - } else if (memberName.equals("max_upload_size")) { - this.maxUploadSize = Double.valueOf(value.toString()).longValue(); - } else if (memberName.equals("status")) { - this.status = Status.fromJSONValue(value.asString()); - } else if (memberName.equals("job_title")) { - this.jobTitle = value.asString(); - } else if (memberName.equals("phone")) { - this.phone = value.asString(); - } else if (memberName.equals("address")) { - this.address = value.asString(); - } else if (memberName.equals("avatar_url")) { - this.avatarURL = value.asString(); - } else if (memberName.equals("notification_email")) { - if (value.isObject()) { - this.notificationEmail = new BoxNotificationEmail(value.asObject()); - } else { - this.notificationEmail = null; - } - } else if (memberName.equals("can_see_managed_users")) { - this.canSeeManagedUsers = value.asBoolean(); - } else if (memberName.equals("is_sync_enabled")) { - this.isSyncEnabled = value.asBoolean(); - } else if (memberName.equals("is_external_collab_restricted")) { - this.isExternalCollabRestricted = value.asBoolean(); - } else if (memberName.equals("is_exempt_from_device_limits")) { - this.isExemptFromDeviceLimits = value.asBoolean(); - } else if (memberName.equals("is_exempt_from_login_verification")) { - this.isExemptFromLoginVerification = value.asBoolean(); - } else if (memberName.equals("is_password_reset_required")) { - this.isPasswordResetRequired = value.asBoolean(); - } else if (memberName.equals("is_platform_access_only")) { - this.isPlatformAccessOnly = value.asBoolean(); - } else if (memberName.equals("external_app_user_id")) { - this.externalAppUserId = value.asString(); - } else if (memberName.equals("enterprise")) { - JsonObject jsonObject = value.asObject(); - if (this.enterprise == null) { - this.enterprise = new BoxEnterprise(jsonObject); - } else { - this.enterprise.update(jsonObject); - } - } else if (memberName.equals("my_tags")) { - this.myTags = this.parseMyTags(value.asArray()); - } else if (memberName.equals("hostname")) { - this.hostname = value.asString(); - } else if (memberName.equals("tracking_codes")) { - this.trackingCodes = this.parseTrackingCodes(value.asArray()); + switch (memberName) { + case "login": + this.login = value.asString(); + break; + case "role": + this.role = Role.fromJSONValue(value.asString()); + break; + case "language": + this.language = value.asString(); + break; + case "timezone": + this.timezone = value.asString(); + break; + case "space_amount": + this.spaceAmount = Double.valueOf(value.toString()).longValue(); + break; + case "space_used": + this.spaceUsed = Double.valueOf(value.toString()).longValue(); + break; + case "max_upload_size": + this.maxUploadSize = Double.valueOf(value.toString()).longValue(); + break; + case "status": + this.status = Status.fromJSONValue(value.asString()); + break; + case "job_title": + this.jobTitle = value.asString(); + break; + case "phone": + this.phone = value.asString(); + break; + case "address": + this.address = value.asString(); + break; + case "avatar_url": + this.avatarURL = value.asString(); + break; + case "notification_email": + if (value.isObject()) { + this.notificationEmail = new BoxNotificationEmail(value.asObject()); + } else { + this.notificationEmail = null; + } + break; + case "can_see_managed_users": + this.canSeeManagedUsers = value.asBoolean(); + break; + case "is_sync_enabled": + this.isSyncEnabled = value.asBoolean(); + break; + case "is_external_collab_restricted": + this.isExternalCollabRestricted = value.asBoolean(); + break; + case "is_exempt_from_device_limits": + this.isExemptFromDeviceLimits = value.asBoolean(); + break; + case "is_exempt_from_login_verification": + this.isExemptFromLoginVerification = value.asBoolean(); + break; + case "is_password_reset_required": + this.isPasswordResetRequired = value.asBoolean(); + break; + case "is_platform_access_only": + this.isPlatformAccessOnly = value.asBoolean(); + break; + case "external_app_user_id": + this.externalAppUserId = value.asString(); + break; + case "enterprise": + JsonObject jsonObject = value.asObject(); + if (this.enterprise == null) { + this.enterprise = new BoxEnterprise(jsonObject); + } else { + this.enterprise.update(jsonObject); + } + break; + case "my_tags": + this.myTags = this.parseMyTags(value.asArray()); + break; + case "hostname": + this.hostname = value.asString(); + break; + case "tracking_codes": + this.trackingCodes = this.parseTrackingCodes(value.asArray()); + break; } } catch (Exception e) { throw new BoxDeserializationException(memberName, value.toString(), e); diff --git a/src/test/java/com/box/sdk/BoxCollaborationTest.java b/src/test/java/com/box/sdk/BoxCollaborationTest.java index d6e6390c3..0d37ce7bb 100644 --- a/src/test/java/com/box/sdk/BoxCollaborationTest.java +++ b/src/test/java/com/box/sdk/BoxCollaborationTest.java @@ -9,7 +9,6 @@ import com.eclipsesource.json.JsonObject; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit.WireMockRule; -import java.io.IOException; import java.util.Collection; import java.util.Date; import org.junit.Before; @@ -29,7 +28,7 @@ public void setUpBaseUrl() { } @Test - public void testCreateFileCollaborationSucceeds() throws IOException { + public void testCreateFileCollaborationSucceeds() { final String collaborationURL = "/2.0/collaborations"; final String fileName = "1_1-4_bsp_ball_valve.pdf"; @@ -43,31 +42,28 @@ public void testCreateFileCollaborationSucceeds() throws IOException { BoxUser collaborator = new BoxUser(this.api, "1111"); BoxFile file = new BoxFile(this.api, "12345"); - BoxCollaboration.Info collabInfo = file.collaborate(collaborator, BoxCollaboration.Role.EDITOR, - false, false); + BoxCollaboration.Info collabInfo = file.collaborate( + collaborator, BoxCollaboration.Role.EDITOR, false, false + ); assertFalse(collabInfo.getCanViewPath()); assertEquals(fileName, collabInfo.getItem().getName()); + assertEquals(BoxFile.TYPE, collabInfo.getItem().getType()); + assertEquals(BoxFile.Info.class, collabInfo.getItem().getClass()); assertEquals(BoxCollaboration.Role.EDITOR, collabInfo.getRole()); assertEquals(BoxCollaboration.Status.ACCEPTED, collabInfo.getStatus()); } @Test - public void testAcceptPendingCollaborationSendsCorrectJson() throws IOException { + public void testAcceptPendingCollaborationSendsCorrectJson() { final String collabID = "12345"; final String collaborationURL = "/2.0/collaborations"; final String acceptCollaborationURL = "/2.0/collaborations/" + collabID; - String updatedResult = ""; JsonObject acceptInvite = new JsonObject() .add("status", "accepted"); String result = TestUtils.getFixture("BoxCollaboration/GetPendingCollaborationInfo200"); - - try { - updatedResult = TestUtils.getFixture("BoxCollaboration/UpdateCollaboration200"); - } catch (IOException e) { - System.out.println("Error Getting Fixture:" + e); - } + String updatedResult = TestUtils.getFixture("BoxCollaboration/UpdateCollaboration200"); wireMockRule.stubFor(WireMock.get(WireMock.urlPathEqualTo(collaborationURL)) .withQueryParam("status", WireMock.containing("pending")) @@ -89,7 +85,7 @@ public void testAcceptPendingCollaborationSendsCorrectJson() throws IOException } @Test - public void testGetPendingCollaborationInfoSucceeds() throws IOException { + public void testGetPendingCollaborationInfoSucceeds() { final String collaborationURL = "/2.0/collaborations"; String result = TestUtils.getFixture("BoxCollaboration/GetPendingCollaborationInfo200"); @@ -108,7 +104,7 @@ public void testGetPendingCollaborationInfoSucceeds() throws IOException { } @Test - public void testGetCollaborationsOnFolderSucceeds() throws IOException { + public void testGetCollaborationsOnFolderSucceeds() { final String folderID = "12345"; final String folderName = "Ball Valve Diagram"; final String getFolderCollaborationURL = "/2.0/folders/" + folderID + "/collaborations"; @@ -128,6 +124,8 @@ public void testGetCollaborationsOnFolderSucceeds() throws IOException { assertEquals(BoxCollaboration.Status.ACCEPTED, firstCollabInfo.getStatus()); assertEquals(BoxCollaboration.Role.EDITOR, firstCollabInfo.getRole()); assertEquals(folderName, firstCollabInfo.getItem().getName()); + assertEquals(BoxFolder.TYPE, firstCollabInfo.getItem().getType()); + assertEquals(BoxFolder.Info.class, firstCollabInfo.getItem().getClass()); } @Test @@ -145,7 +143,7 @@ public void testDeletedCollaborationSucceeds() { } @Test - public void testCreateAndEditCollaborationSucceeds() throws IOException { + public void testCreateAndEditCollaborationSucceeds() { final String collabID = "12345"; final String itemName = "Ball Valve Diagram"; final String createCollaborationURL = "/2.0/collaborations"; @@ -212,7 +210,7 @@ public void testCreateAndEditCollaborationSucceeds() throws IOException { } @Test - public void testGetCollaborationInfoSucceeds() throws IOException { + public void testGetCollaborationInfoSucceeds() { final String collabID = "12345"; final String collabItemID = "2222"; final String collabItemName = "Ball Valve Diagram"; @@ -238,7 +236,7 @@ public void testGetCollaborationInfoSucceeds() throws IOException { } @Test - public void testCanViewPathSendsCorrectJson() throws IOException { + public void testCanViewPathSendsCorrectJson() { final String collabID = "12345"; final boolean canViewPathOn = true; final String collaborationURL = "/2.0/collaborations/" + collabID; @@ -263,7 +261,7 @@ public void testCanViewPathSendsCorrectJson() throws IOException { } @Test - public void testGetAccessibleLoginSucceeds() throws IOException { + public void testGetAccessibleLoginSucceeds() { final String collabID = "12345"; final String accessiblyByLogin = "example@test.com"; final String getCollaborationURL = "/2.0/collaborations/" + collabID; @@ -281,7 +279,7 @@ public void testGetAccessibleLoginSucceeds() throws IOException { } @Test - public void testGetInviteEmailSucceeds() throws IOException { + public void testGetInviteEmailSucceeds() { final String collabID = "12345"; final String inviteEmail = "example@test.com"; final String getCollaborationURL = "/2.0/collaborations/" + collabID; diff --git a/src/test/java/com/box/sdk/BoxFileTest.java b/src/test/java/com/box/sdk/BoxFileTest.java index fbe97687d..9a5d05c83 100644 --- a/src/test/java/com/box/sdk/BoxFileTest.java +++ b/src/test/java/com/box/sdk/BoxFileTest.java @@ -17,6 +17,7 @@ import com.eclipsesource.json.JsonObject; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.matching.EqualToJsonPattern; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -125,7 +126,7 @@ public String getJSON() { } @Test - public void testGetFileInfoSucceeds() throws IOException, ParseException { + public void testGetFileInfoSucceeds() throws ParseException { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID; final String fileName = "Example.pdf"; @@ -169,7 +170,7 @@ public void testGetFileInfoSucceeds() throws IOException, ParseException { } @Test(expected = BoxDeserializationException.class) - public void testDeserializationException() throws IOException { + public void testDeserializationException() { final String fileID = "12345"; final String filesURL = "/2.0/files/" + fileID; @@ -185,7 +186,7 @@ public void testDeserializationException() throws IOException { } @Test - public void testRemoveSharedLink() throws IOException { + public void testRemoveSharedLink() { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID; JsonObject jsonObject = new JsonObject() @@ -208,7 +209,7 @@ public void testRemoveSharedLink() throws IOException { } @Test - public void testGetTasksWithFields() throws IOException { + public void testGetTasksWithFields() { final String fileID = "12345"; final String tasksURL = "/2.0/files/" + fileID + "/tasks"; @@ -227,7 +228,7 @@ public void testGetTasksWithFields() throws IOException { } @Test - public void testUpdateFileInformationSucceedsAndSendsCorrectJson() throws IOException { + public void testUpdateFileInformationSucceedsAndSendsCorrectJson() { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID; final String newFileName = "New File Name"; @@ -251,7 +252,7 @@ public void testUpdateFileInformationSucceedsAndSendsCorrectJson() throws IOExce } @Test - public void testCopyFileSucceedsAndSendsCorrectJson() throws IOException { + public void testCopyFileSucceedsAndSendsCorrectJson() { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID + "/copy"; final String parentID = "0"; @@ -278,7 +279,7 @@ public void testCopyFileSucceedsAndSendsCorrectJson() throws IOException { } @Test - public void testMoveFileSucceedsAndSendsCorrectJson() throws IOException { + public void testMoveFileSucceedsAndSendsCorrectJson() { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID; final String newParentID = "1111"; @@ -320,7 +321,7 @@ public void testDeleteFileSucceeds() { } @Test - public void testLockFileSucceedsAndSendsCorrectJson() throws IOException { + public void testLockFileSucceedsAndSendsCorrectJson() { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID; final boolean isDownloadPrevented = true; @@ -350,7 +351,7 @@ public void testLockFileSucceedsAndSendsCorrectJson() throws IOException { } @Test - public void testUnlockFileSucceedsAndSendSendsCorrectJson() throws IOException { + public void testUnlockFileSucceedsAndSendSendsCorrectJson() { final String fileID = "12345"; final String fileURL = "/2.0/files/" + fileID; JsonObject unlockObject = new JsonObject().add("lock", Json.NULL); @@ -407,7 +408,7 @@ public void testGetThumbnailSucceeds() { } @Test - public void testDeletePreviousFileVersionSucceeds() throws IOException { + public void testDeletePreviousFileVersionSucceeds() { final String versionID = "12345"; final String fileID = "1111"; final String fileURL = "/2.0/files/" + fileID + "/versions"; @@ -439,7 +440,7 @@ public void testDeletePreviousFileVersionSucceeds() throws IOException { } @Test - public void testCreateMetadataOnFileSucceeds() throws IOException { + public void testCreateMetadataOnFileSucceeds() { final String metadataID = "12345"; final String fileID = "12345"; final String scope = "global"; @@ -463,7 +464,7 @@ public void testCreateMetadataOnFileSucceeds() throws IOException { } @Test - public void testGetMetadataOnFileSucceeds() throws IOException { + public void testGetMetadataOnFileSucceeds() { final String fileID = "12345"; final String metadataID = "12345"; final String parent = "file_1111"; @@ -488,7 +489,7 @@ public void testGetMetadataOnFileSucceeds() throws IOException { } @Test - public void testUploadNewVersionReturnsCorrectInfo() throws IOException { + public void testUploadNewVersionReturnsCorrectInfo() { String fileID = "11111"; String fileName = "test.txt"; byte[] bytes = new byte[]{1, 2, 3}; @@ -510,7 +511,7 @@ public void testUploadNewVersionReturnsCorrectInfo() throws IOException { } @Test - public void createSharedLinkSucceeds() throws IOException { + public void createSharedLinkSucceeds() { final String fileID = "1111"; final String password = "test1"; @@ -549,7 +550,7 @@ public void createSharedLinkSucceeds() throws IOException { } @Test - public void createEditableSharedLinkSucceeds() throws IOException { + public void createEditableSharedLinkSucceeds() { final String fileID = "1111"; final String password = "test1"; @@ -586,7 +587,7 @@ public void createEditableSharedLinkSucceeds() throws IOException { } @Test - public void testAddClassification() throws IOException { + public void testAddClassification() { final String fileID = "12345"; final String classificationType = "Public"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -608,7 +609,7 @@ public void testAddClassification() throws IOException { } @Test - public void testUpdateClassification() throws IOException { + public void testUpdateClassification() { final String fileID = "12345"; final String classificationType = "Internal"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -635,7 +636,7 @@ public void testUpdateClassification() throws IOException { } @Test - public void testSetClassification() throws IOException { + public void testSetClassification() { final String fileID = "12345"; final String classificationType = "Internal"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -680,7 +681,7 @@ public void testSetClassificationThrowsException() { } @Test - public void testGetClassification() throws IOException { + public void testGetClassification() { final String fileID = "12345"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -698,7 +699,7 @@ public void testGetClassification() throws IOException { } @Test - public void testGetClassificationReturnsNone() throws IOException { + public void testGetClassificationReturnsNone() { final String fileID = "12345"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -717,7 +718,7 @@ public void testGetClassificationReturnsNone() throws IOException { } @Test(expected = BoxAPIException.class) - public void testGetClassificationThrows() throws IOException { + public void testGetClassificationThrows() { final String fileID = "12345"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -748,7 +749,7 @@ public void testDeleteClassification() { } @Test - public void testSetMetadataReturnsCorrectly() throws IOException { + public void testSetMetadataReturnsCorrectly() { final String fileID = "12345"; final String metadataURL = "/2.0/files/" + fileID + "/metadata/enterprise/testtemplate"; ArrayList secondValueArray = new ArrayList<>(); @@ -1066,7 +1067,7 @@ public String getJSON() { } @Test - public void setsDispositionAt() throws ParseException, IOException { + public void setsDispositionAt() throws ParseException { //given String fileId = "12345"; final String fileURL = "/2.0/files/" + fileId; @@ -1127,4 +1128,20 @@ public int read(byte[] b, int offset, int len) { return 1; } } + + @Test + public void renameFile() { + final String fileID = "12345"; + final String metadataURL = "/2.0/files/" + fileID; + String result = TestUtils.getFixture("BoxFile/GetFileInfo200"); + + wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(metadataURL)) + .withRequestBody(new EqualToJsonPattern("{\"name\": \"New Name\"}", false, false)) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result) + .withStatus(200))); + + new BoxFile(this.api, fileID).rename("New Name"); + } } diff --git a/src/test/java/com/box/sdk/BoxFolderTest.java b/src/test/java/com/box/sdk/BoxFolderTest.java index 59fa815ba..dc8618db0 100644 --- a/src/test/java/com/box/sdk/BoxFolderTest.java +++ b/src/test/java/com/box/sdk/BoxFolderTest.java @@ -20,6 +20,7 @@ import com.eclipsesource.json.JsonObject; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.matching.EqualToJsonPattern; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -455,7 +456,7 @@ public void testRetryingChunkedUploadWith500Error() throws IOException, Interrup } @Test - public void testGetAllRootFolderItemsSucceeds() throws IOException { + public void testGetAllRootFolderItemsSucceeds() { final String rootFolderItemsURL = "/2.0/folders/0/items/"; final String folderURL = "/2.0/folders/0"; final String ownedByUserLogin = "test@user.com"; @@ -483,7 +484,7 @@ public void testGetAllRootFolderItemsSucceeds() throws IOException { } @Test - public void testGetAllFolderItemsSucceeds() throws IOException { + public void testGetAllFolderItemsSucceeds() { final String folderID = "12345"; final String folderURL = "/2.0/folders/" + folderID + "/items/"; final String firstFolderName = "Example.pdf"; @@ -505,7 +506,7 @@ public void testGetAllFolderItemsSucceeds() throws IOException { } @Test - public void testGetFolderInfoSucceeds() throws IOException { + public void testGetFolderInfoSucceeds() { final String folderID = "12345"; final String folderInfoURL = "/2.0/folders/" + folderID; final String folderName = "Example Folder"; @@ -544,7 +545,7 @@ public void testGetFolderInfoSucceeds() throws IOException { } @Test - public void testGetRestrictedCollaborationFieldSucceeds() throws IOException { + public void testGetRestrictedCollaborationFieldSucceeds() { final String folderID = "12345"; final String folderInfoURL = "/2.0/folders/" + folderID; @@ -562,7 +563,7 @@ public void testGetRestrictedCollaborationFieldSucceeds() throws IOException { } @Test - public void testSetRestrictedCollaborationFieldSucceeds() throws IOException { + public void testSetRestrictedCollaborationFieldSucceeds() { final String folderID = "12345"; final String folderInfoURL = "/2.0/folders/" + folderID; JsonObject jsonObject = new JsonObject() @@ -590,7 +591,7 @@ public void testSetRestrictedCollaborationFieldSucceeds() throws IOException { } @Test - public void testUpdateFolderInfoSucceedsAndSendsCorrectJson() throws IOException { + public void testUpdateFolderInfoSucceedsAndSendsCorrectJson() { final String folderID = "12345"; final String folderURL = "/2.0/folders/" + folderID; final String folderName = "New Folder Name"; @@ -626,7 +627,7 @@ public void testUpdateFolderInfoSucceedsAndSendsCorrectJson() throws IOException } @Test - public void testCreateNewFolderSucceedsAndSendsCorrectJson() throws IOException { + public void testCreateNewFolderSucceedsAndSendsCorrectJson() { final String folderID = "0"; final String folderURL = "/2.0/folders"; final String folderName = "Example Test Folder"; @@ -660,7 +661,7 @@ public void testCreateNewFolderSucceedsAndSendsCorrectJson() throws IOException } @Test - public void testCopyFolderSucceedsAndSendsCorrectJson() throws IOException { + public void testCopyFolderSucceedsAndSendsCorrectJson() { final String folderID = "12345"; final String folderURL = "/2.0/folders/" + folderID + "/copy"; final String newParentID = "12345"; @@ -688,7 +689,7 @@ public void testCopyFolderSucceedsAndSendsCorrectJson() throws IOException { } @Test - public void testMoveFolderSucceedsAndSendsCorrectJson() throws IOException { + public void testMoveFolderSucceedsAndSendsCorrectJson() { final String folderID = "12345"; final String moveFolderURL = "/2.0/folders/" + folderID; final String parentID = "2222"; @@ -731,7 +732,7 @@ public void testDeleteFolderSendsCorrectJson() { } @Test - public void testCreateSharedLinkForFolderSucceedsAndSendsCorrectJson() throws IOException { + public void testCreateSharedLinkForFolderSucceedsAndSendsCorrectJson() { final String folderID = "12345"; final String folderURL = "/2.0/folders/" + folderID; @@ -763,7 +764,7 @@ public void testCreateSharedLinkForFolderSucceedsAndSendsCorrectJson() throws IO } @Test - public void testGetAllFolderCollaborationsSucceeds() throws IOException { + public void testGetAllFolderCollaborationsSucceeds() { final String folderID = "3333"; final String folderCollaborationURL = "/2.0/folders/" + folderID + "/collaborations"; final String collaborationID = "12345"; @@ -793,7 +794,7 @@ public void testGetAllFolderCollaborationsSucceeds() throws IOException { } @Test - public void testCreateMetadataOnFolderSucceedsAndSendsCorrectJson() throws IOException { + public void testCreateMetadataOnFolderSucceedsAndSendsCorrectJson() { final String folderID = "12345"; final String metadataURL = "/2.0/folders/" + folderID + "/metadata/global/properties"; final String metadataID = "12345"; @@ -817,7 +818,7 @@ public void testCreateMetadataOnFolderSucceedsAndSendsCorrectJson() throws IOExc } @Test - public void testGetMetadataOnFolderSucceds() throws IOException { + public void testGetMetadataOnFolderSucceds() { final String folderID = "12345"; final String metadataURL = "/2.0/folders/" + folderID + "/metadata/global/properties"; final String metadataID = "12345"; @@ -838,7 +839,7 @@ public void testGetMetadataOnFolderSucceds() throws IOException { } @Test - public void testGetAllMetadataSucceeds() throws IOException { + public void testGetAllMetadataSucceeds() { final String folderID = "12345"; final String metadataURL = "/2.0/folders/" + folderID + "/metadata"; final String metadataID = "12345"; @@ -865,7 +866,7 @@ public void testGetAllMetadataSucceeds() throws IOException { } @Test - public void testAddMetadataCascadePolicySucceedsSendsCorrectJson() throws IOException { + public void testAddMetadataCascadePolicySucceedsSendsCorrectJson() { final String cascadePolicyURL = "/2.0/metadata_cascade_policies"; final String folderID = "22222"; final String scope = "enterprise_11111"; @@ -892,7 +893,7 @@ public void testAddMetadataCascadePolicySucceedsSendsCorrectJson() throws IOExce } @Test - public void testGetAllMetadataCascadePoliciesOnFolderSucceeds() throws IOException { + public void testGetAllMetadataCascadePoliciesOnFolderSucceeds() { final String folderID = "22222"; final String cascadePolicyID = "84113349-794d-445c-b93c-d8481b223434"; final String enterpriseID = "11111"; @@ -922,7 +923,7 @@ public void testGetAllMetadataCascadePoliciesOnFolderSucceeds() throws IOExcepti } @Test - public void testGetAllMetadataCascadePoliciesOnFolderWithFieldsSucceeds() throws IOException { + public void testGetAllMetadataCascadePoliciesOnFolderWithFieldsSucceeds() { final String folderID = "22222"; final String cascadePolicyID = "84113349-794d-445c-b93c-d8481b223434"; final String enterpriseID = "11111"; @@ -954,7 +955,7 @@ public void testGetAllMetadataCascadePoliciesOnFolderWithFieldsSucceeds() throws } @Test - public void testGetAllMetadataCascadePoliciesWithEnterpriseIDSucceeds() throws IOException { + public void testGetAllMetadataCascadePoliciesWithEnterpriseIDSucceeds() { final String folderID = "22222"; final String cascadePolicyID = "84113349-794d-445c-b93c-d8481b223434"; final String enterpriseID = "11111"; @@ -988,7 +989,7 @@ public void testGetAllMetadataCascadePoliciesWithEnterpriseIDSucceeds() throws I } @Test - public void createSharedLinkSucceeds() throws IOException { + public void createSharedLinkSucceeds() { final String folderID = "1111"; final String password = "test1"; @@ -1026,7 +1027,7 @@ public void createSharedLinkSucceeds() throws IOException { } @Test - public void createSharedLinkChangesCanEditPermissionToFalse() throws IOException { + public void createSharedLinkChangesCanEditPermissionToFalse() { final String folderID = "1111"; final String password = "test1"; @@ -1061,7 +1062,7 @@ public void createSharedLinkChangesCanEditPermissionToFalse() throws IOException } @Test - public void testAddClassification() throws IOException { + public void testAddClassification() { final String folderID = "12345"; final String classificationType = "Public"; final String metadataURL = "/2.0/folders/" + folderID @@ -1084,7 +1085,7 @@ public void testAddClassification() throws IOException { } @Test - public void testUpdateClassification() throws IOException { + public void testUpdateClassification() { final String folderID = "12345"; final String classificationType = "Internal"; final String metadataURL = "/2.0/folders/" + folderID @@ -1112,7 +1113,7 @@ public void testUpdateClassification() throws IOException { } @Test - public void testSetClassification() throws IOException { + public void testSetClassification() { final String folderID = "12345"; final String classificationType = "Internal"; final String metadataURL = "/2.0/folders/" + folderID @@ -1161,7 +1162,7 @@ public void testSetClassificationThrowsException() { } @Test - public void testGetClassification() throws IOException { + public void testGetClassification() { final String folderID = "12345"; final String metadataURL = "/2.0/folders/" + folderID + "/metadata/enterprise/securityClassification-6VMVochwUWo"; @@ -1197,7 +1198,7 @@ public void testDeleteClassification() { } @Test - public void testUploadFileWithDescriptionSucceeds() throws IOException { + public void testUploadFileWithDescriptionSucceeds() { final String folderID = "12345"; final String fileURL = "/2.0/files/content"; final String fileContent = "Test file"; @@ -1220,7 +1221,7 @@ public void testUploadFileWithDescriptionSucceeds() throws IOException { } @Test - public void testGetFolderItemsWithSortAndOffset() throws IOException { + public void testGetFolderItemsWithSortAndOffset() { final String folderID = "12345"; final String folderItemsURL = "/2.0/folders/" + folderID + "/items/"; @@ -1247,7 +1248,7 @@ public void testGetFolderItemsWithSortAndOffset() throws IOException { } @Test - public void testGetFolderItemsWithOffsetAndLimit() throws IOException { + public void testGetFolderItemsWithOffsetAndLimit() { final String folderID = "12345"; final String folderItemsURL = "/2.0/folders/" + folderID + "/items/"; @@ -1284,7 +1285,7 @@ public void testGetFolderItemsWithSortAndMarkerBasedPagingFails() { } @Test - public void testSetMetadataReturnsCorrectly() throws IOException { + public void testSetMetadataReturnsCorrectly() { final String folderID = "12345"; final String metadataURL = "/2.0/folders/" + folderID + "/metadata/enterprise/testtemplate"; ArrayList secondValueArray = new ArrayList<>(); @@ -1372,7 +1373,7 @@ public void testSetMetadataReturnsCorrectly() throws IOException { } @Test(expected = BoxDeserializationException.class) - public void testDeserializationException() throws IOException { + public void testDeserializationException() { final String folderID = "12345"; final String foldersURL = "/2.0/folders/" + folderID; @@ -1388,7 +1389,7 @@ public void testDeserializationException() throws IOException { } @Test - public void createFolderLockSucceeds() throws IOException { + public void createFolderLockSucceeds() { final String folderID = "12345678"; final String folderLockURL = "/2.0/folder_locks"; @@ -1421,7 +1422,7 @@ public void createFolderLockSucceeds() throws IOException { } @Test - public void getFolderLocks() throws IOException { + public void getFolderLocks() { final String folderID = "12345"; final String folderLocksURL = "/2.0/folder_locks"; @@ -1550,4 +1551,20 @@ public String getJSON() { assertThat(postCounter.get(), is(1)); assertThat(getCounter.get(), is(1)); } + + @Test + public void renameFolder() { + final String folderId = "12345"; + final String metadataURL = "/2.0/folders/" + folderId; + String result = TestUtils.getFixture("BoxFolder/GetFolderInfo200"); + + wireMockRule.stubFor(WireMock.put(WireMock.urlPathEqualTo(metadataURL)) + .withRequestBody(new EqualToJsonPattern("{\"name\": \"New Name\"}", false, false)) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result) + .withStatus(200))); + + new BoxFolder(this.api, folderId).rename("New Name"); + } } diff --git a/src/test/java/com/box/sdk/BoxUserTest.java b/src/test/java/com/box/sdk/BoxUserTest.java index 917d3cfd8..f5be4d73f 100644 --- a/src/test/java/com/box/sdk/BoxUserTest.java +++ b/src/test/java/com/box/sdk/BoxUserTest.java @@ -252,17 +252,33 @@ public void testUpdateUserInfoSucceedsAndSendsCorrectJson() throws IOException { } @Test - public void testDeleteUserSucceeds() { + public void testDeleteUserWithParamsSucceeds() { final String userID = "12345"; final String userURL = "/2.0/users/" + userID; wireMockRule.stubFor(WireMock.delete(WireMock.urlPathEqualTo(userURL)) + .withQueryParam("force", new EqualToPattern("false")) + .withQueryParam("notify", new EqualToPattern("false")) .willReturn(WireMock.noContent())); BoxUser user = new BoxUser(this.api, userID); user.delete(false, false); } + @Test + public void testDeleteUserSucceeds() { + final String userID = "12345"; + final String userURL = "/2.0/users/" + userID; + + wireMockRule.stubFor(WireMock.delete(WireMock.urlPathEqualTo(userURL)) + // we expect no query params will be sent + .withQueryParams(new HashMap<>()) + .willReturn(WireMock.noContent())); + + BoxUser user = new BoxUser(this.api, userID); + user.delete(); + } + @Test public void testCreateEmailAliasSucceeds() throws IOException { final String userID = "12345"; diff --git a/src/test/java/com/box/sdk/TestUtils.java b/src/test/java/com/box/sdk/TestUtils.java index cd66abb55..18337b6d1 100644 --- a/src/test/java/com/box/sdk/TestUtils.java +++ b/src/test/java/com/box/sdk/TestUtils.java @@ -17,7 +17,7 @@ public static BoxAPIConnection getAPIConnection() { /** * Util function to help get JSON fixtures for tests. */ - public static String getFixture(String fixtureName) throws IOException { + public static String getFixture(String fixtureName) { String fixtureFullPath = "./src/test/Fixtures/" + fixtureName + ".json"; try (BufferedReader reader = new BufferedReader(new FileReader(fixtureFullPath))) { StringBuilder builder = new StringBuilder(); @@ -29,6 +29,8 @@ public static String getFixture(String fixtureName) throws IOException { line = reader.readLine(); } return builder.toString(); + } catch (IOException e) { + throw new RuntimeException(e); } }