From 27fd25423a1e91b3a2bfd5208ef33de2196613de Mon Sep 17 00:00:00 2001 From: carycheng Date: Mon, 2 Jul 2018 11:51:02 -0700 Subject: [PATCH 1/5] added function to set password --- src/main/java/com/box/sdk/BoxSharedLink.java | 10 +++ .../CreateSharedLinkWithPassword201.json | 82 +++++++++++++++++++ src/test/java/com/box/sdk/BoxFileTest.java | 65 +++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 src/test/Fixtures/BoxFile/CreateSharedLinkWithPassword201.json diff --git a/src/main/java/com/box/sdk/BoxSharedLink.java b/src/main/java/com/box/sdk/BoxSharedLink.java index b3737b59d..f021ad58e 100644 --- a/src/main/java/com/box/sdk/BoxSharedLink.java +++ b/src/main/java/com/box/sdk/BoxSharedLink.java @@ -14,6 +14,7 @@ public class BoxSharedLink extends BoxJSONObject { private String downloadUrl; private String vanityUrl; private boolean isPasswordEnabled; + private String password; private Date unsharedAt; private long downloadCount; private long previewCount; @@ -129,6 +130,15 @@ public void setAccess(Access access) { this.addPendingChange("access", access.toJSONValue()); } + /** + * Sets the password of this shared link. + * @param password the password of this shared link. + */ + public void setPassword(String password) { + this.password = password; + this.addPendingChange("password", password.toString()); + } + /** * Gets the effective access level of this shared link. * @return the effective access level of this shared link. diff --git a/src/test/Fixtures/BoxFile/CreateSharedLinkWithPassword201.json b/src/test/Fixtures/BoxFile/CreateSharedLinkWithPassword201.json new file mode 100644 index 000000000..c3f46cc09 --- /dev/null +++ b/src/test/Fixtures/BoxFile/CreateSharedLinkWithPassword201.json @@ -0,0 +1,82 @@ +{ + "type": "file", + "id": "1111", + "file_version": { + "type": "file_version", + "id": "2222", + "sha1": "a9225c82fdce3e5701111976de462c22a76df7ee" + }, + "sequence_id": "1", + "etag": "1", + "sha1": "a9225c82fdce3e5701111976de462c22a76df7ee", + "name": "test.png", + "description": "", + "size": 2882774, + "path_collection": { + "total_count": 2, + "entries": [ + { + "type": "folder", + "id": "0", + "sequence_id": null, + "etag": null, + "name": "All Files" + }, + { + "type": "folder", + "id": "3333", + "sequence_id": "0", + "etag": "0", + "name": "Test Folder" + } + ] + }, + "created_at": "2018-07-02T10:29:20-07:00", + "modified_at": "2018-07-02T10:29:22-07:00", + "trashed_at": null, + "purged_at": null, + "content_created_at": "2018-04-30T15:36:09-07:00", + "content_modified_at": "2018-04-30T15:36:09-07:00", + "created_by": { + "type": "user", + "id": "1111", + "name": "Test User", + "login": "test@example.com" + }, + "modified_by": { + "type": "user", + "id": "1111", + "name": "Test User", + "login": "test@example.com" + }, + "owned_by": { + "type": "user", + "id": "1111", + "name": "Test User", + "login": "test@example.com" + }, + "shared_link": { + "url": "https://testt3t2t2t2.box.com/s/12345", + "download_url": "https://testt3t2t2t2.box.com/shared/static/12345.png", + "vanity_url": null, + "effective_access": "open", + "effective_permission": "can_download", + "is_password_enabled": true, + "unshared_at": null, + "download_count": 0, + "preview_count": 0, + "access": "open", + "permissions": { + "can_preview": true, + "can_download": true + } + }, + "parent": { + "type": "folder", + "id": "5555", + "sequence_id": "0", + "etag": "0", + "name": "Test Folder" + }, + "item_status": "active" +} diff --git a/src/test/java/com/box/sdk/BoxFileTest.java b/src/test/java/com/box/sdk/BoxFileTest.java index 89e1aa474..2312a78aa 100644 --- a/src/test/java/com/box/sdk/BoxFileTest.java +++ b/src/test/java/com/box/sdk/BoxFileTest.java @@ -43,6 +43,7 @@ import org.junit.experimental.categories.Category; import com.eclipsesource.json.JsonObject; +import sun.tools.jconsole.Plotter; /** * {@link BoxFile} related unit tests. @@ -1394,6 +1395,70 @@ public void testUploadNewVersionReturnsCorrectInfo() throws IOException { Assert.assertEquals(fileName, info.getName()); } + @Test + @Category(UnitTest.class) + public void createSharedLinkWithPasswordSucceeds() throws IOException{ + final String fileID = "1111"; + final String password = "test1"; + String result = ""; + + JsonObject innerObject = new JsonObject() + .add("password", password); + + JsonObject sharedLinkObject = new JsonObject() + .add("shared_link", innerObject); + + result = TestConfig.getFixture("BoxFile/CreateSharedLinkWithPassword201"); + + WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(200))); + + WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result))); + + WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) + .withRequestBody(WireMock.equalToJson(sharedLinkObject.toString())) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result))); + + BoxFile file = new BoxFile(this.api, fileID); + BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); + + permissions.setCanDownload(true); + permissions.setCanPreview(true); + BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions); + + sharedLink.setPassword(password); + BoxFile.Info info = file.new Info(); + info.setSharedLink(sharedLink); + file.updateInfo(info); + + Assert.assertEquals(true, info.getSharedLink().getIsPasswordEnabled()); + } + + @Test + @Category(IntegrationTest.class) + public void createSharedLinkWithPassword() { + BoxAPIConnection api = new BoxAPIConnection("YjwhWT6etFjhojWBSFhIsMfPXdX7PcMy"); + BoxFile file = new BoxFile(api, "302103488352"); + BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); + String password = "test1234"; + + permissions.setCanDownload(true); + permissions.setCanPreview(true); + BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions); + + sharedLink.setPassword(password); + BoxFile.Info info = file.new Info(); + info.setSharedLink(sharedLink); + file.updateInfo(info); + } + private BoxFile.Info parallelMuliputUpload(File file, BoxFolder folder, String fileName) throws IOException, InterruptedException { FileInputStream newStream = new FileInputStream(file); From 1ad77f34e4c57689ac5643d6a14b246b3ecf2c24 Mon Sep 17 00:00:00 2001 From: carycheng Date: Mon, 2 Jul 2018 11:56:06 -0700 Subject: [PATCH 2/5] fixed style errors --- src/test/java/com/box/sdk/BoxFileTest.java | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/test/java/com/box/sdk/BoxFileTest.java b/src/test/java/com/box/sdk/BoxFileTest.java index 2312a78aa..32c9c8408 100644 --- a/src/test/java/com/box/sdk/BoxFileTest.java +++ b/src/test/java/com/box/sdk/BoxFileTest.java @@ -43,7 +43,6 @@ import org.junit.experimental.categories.Category; import com.eclipsesource.json.JsonObject; -import sun.tools.jconsole.Plotter; /** * {@link BoxFile} related unit tests. @@ -1397,7 +1396,7 @@ public void testUploadNewVersionReturnsCorrectInfo() throws IOException { @Test @Category(UnitTest.class) - public void createSharedLinkWithPasswordSucceeds() throws IOException{ + public void createSharedLinkWithPasswordSucceeds() throws IOException { final String fileID = "1111"; final String password = "test1"; String result = ""; @@ -1441,24 +1440,6 @@ public void createSharedLinkWithPasswordSucceeds() throws IOException{ Assert.assertEquals(true, info.getSharedLink().getIsPasswordEnabled()); } - @Test - @Category(IntegrationTest.class) - public void createSharedLinkWithPassword() { - BoxAPIConnection api = new BoxAPIConnection("YjwhWT6etFjhojWBSFhIsMfPXdX7PcMy"); - BoxFile file = new BoxFile(api, "302103488352"); - BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); - String password = "test1234"; - - permissions.setCanDownload(true); - permissions.setCanPreview(true); - BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions); - - sharedLink.setPassword(password); - BoxFile.Info info = file.new Info(); - info.setSharedLink(sharedLink); - file.updateInfo(info); - } - private BoxFile.Info parallelMuliputUpload(File file, BoxFolder folder, String fileName) throws IOException, InterruptedException { FileInputStream newStream = new FileInputStream(file); From 87c0758eb91c718cf93a1c98eb8a62d84ce169d6 Mon Sep 17 00:00:00 2001 From: carycheng Date: Mon, 2 Jul 2018 15:07:57 -0700 Subject: [PATCH 3/5] updated constructors for links --- src/main/java/com/box/sdk/BoxFile.java | 11 +++++++++++ src/main/java/com/box/sdk/BoxFolder.java | 11 +++++++++++ src/main/java/com/box/sdk/BoxSharedLink.java | 9 +++++++++ src/main/java/com/box/sdk/BoxWebLink.java | 11 +++++++++++ .../CreateSharedLinkForFile201.json | 16 ++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json diff --git a/src/main/java/com/box/sdk/BoxFile.java b/src/main/java/com/box/sdk/BoxFile.java index f9a8a1541..3f1d2b953 100644 --- a/src/main/java/com/box/sdk/BoxFile.java +++ b/src/main/java/com/box/sdk/BoxFile.java @@ -159,6 +159,17 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD return info.getSharedLink(); } + public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, + BoxSharedLink.Permissions permissions, String password) { + + BoxSharedLink sharedLink = new BoxSharedLink(access, unshareDate, permissions, password); + Info info = new Info(); + info.setSharedLink(sharedLink); + + this.updateInfo(info); + return info.getSharedLink(); + } + /** * Adds new {@link BoxWebHook} to this {@link BoxFile}. * diff --git a/src/main/java/com/box/sdk/BoxFolder.java b/src/main/java/com/box/sdk/BoxFolder.java index 3b8a5b711..a327e4de8 100644 --- a/src/main/java/com/box/sdk/BoxFolder.java +++ b/src/main/java/com/box/sdk/BoxFolder.java @@ -220,6 +220,17 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD return info.getSharedLink(); } + public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, + BoxSharedLink.Permissions permissions, String password) { + + BoxSharedLink sharedLink = new BoxSharedLink(access, unshareDate, permissions, password); + Info info = new Info(); + info.setSharedLink(sharedLink); + + this.updateInfo(info); + return info.getSharedLink(); + } + /** * Gets information about all of the collaborations for this folder. * diff --git a/src/main/java/com/box/sdk/BoxSharedLink.java b/src/main/java/com/box/sdk/BoxSharedLink.java index f021ad58e..89690d920 100644 --- a/src/main/java/com/box/sdk/BoxSharedLink.java +++ b/src/main/java/com/box/sdk/BoxSharedLink.java @@ -47,6 +47,15 @@ public BoxSharedLink(String json) { this.setUnsharedDate(unshareDate); } } + BoxSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions, String password) { + this.setAccess(access); + this.setPermissions(permissions); + this.setPassword(password); + + if (unshareDate != null) { + this.setUnsharedDate(unshareDate); + } + } /** * Get the URL of this shared link. diff --git a/src/main/java/com/box/sdk/BoxWebLink.java b/src/main/java/com/box/sdk/BoxWebLink.java index e701a8109..b8bb1929e 100644 --- a/src/main/java/com/box/sdk/BoxWebLink.java +++ b/src/main/java/com/box/sdk/BoxWebLink.java @@ -56,6 +56,17 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD return info.getSharedLink(); } + public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, + BoxSharedLink.Permissions permissions, String password) { + + BoxSharedLink sharedLink = new BoxSharedLink(access, unshareDate, permissions, password); + Info info = new Info(); + info.setSharedLink(sharedLink); + + this.updateInfo(info); + return info.getSharedLink(); + } + @Override public BoxWebLink.Info copy(BoxFolder destination) { return this.copy(destination, null); diff --git a/src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json b/src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json new file mode 100644 index 000000000..9db6ec3b8 --- /dev/null +++ b/src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json @@ -0,0 +1,16 @@ +"shared_link": { + "url": "https://testt3t2t2t2.box.com/s/12345", + "download_url": "https://testt3t2t2t2.box.com/shared/static/12345.png", + "vanity_url": null, + "effective_access": "open", + "effective_permission": "can_download", + "is_password_enabled": true, + "unshared_at": null, + "download_count": 0, + "preview_count": 0, + "access": "open", + "permissions": { + "can_preview": true, + "can_download": true + } +}, From eba7db94e0850376988eb047782532bed3671de0 Mon Sep 17 00:00:00 2001 From: carycheng Date: Wed, 4 Jul 2018 18:00:29 -0700 Subject: [PATCH 4/5] file test fixture --- src/test/java/com/box/sdk/BoxFileTest.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/java/com/box/sdk/BoxFileTest.java b/src/test/java/com/box/sdk/BoxFileTest.java index 32c9c8408..ea9d360ad 100644 --- a/src/test/java/com/box/sdk/BoxFileTest.java +++ b/src/test/java/com/box/sdk/BoxFileTest.java @@ -1394,6 +1394,38 @@ public void testUploadNewVersionReturnsCorrectInfo() throws IOException { Assert.assertEquals(fileName, info.getName()); } + @Test + @Category(UnitTest.class) + public void createSharedLinkSucceeds() throws IOException { + final String fileID = "1111"; + final String password = "test1"; + String result = ""; + + JsonObject innerObject = new JsonObject() + .add("password", password); + + JsonObject sharedLinkObject = new JsonObject() + .add("shared_link", innerObject); + + result = TestConfig.getFixture("BoxSharedLink/CreateSharedLinkForFile201"); + + WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) + .withRequestBody(WireMock.equalToJson(sharedLinkObject.toString())) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result))); + + BoxFile file = new BoxFile(this.api, fileID); + BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); + + permissions.setCanDownload(true); + permissions.setCanPreview(true); + BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions, + password); + + Assert.assertEquals(true, sharedLink.getIsPasswordEnabled()); + } + @Test @Category(UnitTest.class) public void createSharedLinkWithPasswordSucceeds() throws IOException { From 56634df818e1f29351c86b5836096c4018343b3b Mon Sep 17 00:00:00 2001 From: carycheng Date: Thu, 5 Jul 2018 16:14:34 -0700 Subject: [PATCH 5/5] updated for javadoc and added tests --- src/main/java/com/box/sdk/BoxFile.java | 9 +++ src/main/java/com/box/sdk/BoxFolder.java | 9 +++ src/main/java/com/box/sdk/BoxSharedLink.java | 3 +- src/main/java/com/box/sdk/BoxWebLink.java | 9 +++ .../BoxSharedLink/CreateSharedLink201.json | 18 ++++++ .../CreateSharedLinkForFile201.json | 16 ------ src/test/java/com/box/sdk/BoxFileTest.java | 57 +++---------------- src/test/java/com/box/sdk/BoxFolderTest.java | 38 +++++++++++++ src/test/java/com/box/sdk/BoxWebLinkTest.java | 38 +++++++++++++ 9 files changed, 131 insertions(+), 66 deletions(-) create mode 100644 src/test/Fixtures/BoxSharedLink/CreateSharedLink201.json delete mode 100644 src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json diff --git a/src/main/java/com/box/sdk/BoxFile.java b/src/main/java/com/box/sdk/BoxFile.java index 3f1d2b953..70a8dec40 100644 --- a/src/main/java/com/box/sdk/BoxFile.java +++ b/src/main/java/com/box/sdk/BoxFile.java @@ -159,6 +159,15 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD return info.getSharedLink(); } + /** + * Creates new SharedLink for a BoxFile with a password. + * + * @param access The access level of the shared link. + * @param unshareDate A specified date to unshare the Box file. + * @param permissions The permissions to set on the shared link for the Box file. + * @param password Password set on the shared link to give access to the Box file. + * @return information about the newly created shared link. + */ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions, String password) { diff --git a/src/main/java/com/box/sdk/BoxFolder.java b/src/main/java/com/box/sdk/BoxFolder.java index a327e4de8..3831ab3d7 100644 --- a/src/main/java/com/box/sdk/BoxFolder.java +++ b/src/main/java/com/box/sdk/BoxFolder.java @@ -220,6 +220,15 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD return info.getSharedLink(); } + /** + * Creates new SharedLink for a BoxFolder with a password. + * + * @param access The access level of the shared link. + * @param unshareDate A specified date to unshare the Box folder. + * @param permissions The permissions to set on the shared link for the Box folder. + * @param password Password set on the shared link to give access to the Box folder. + * @return information about the newly created shared link. + */ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions, String password) { diff --git a/src/main/java/com/box/sdk/BoxSharedLink.java b/src/main/java/com/box/sdk/BoxSharedLink.java index 89690d920..6c3ead84d 100644 --- a/src/main/java/com/box/sdk/BoxSharedLink.java +++ b/src/main/java/com/box/sdk/BoxSharedLink.java @@ -47,7 +47,8 @@ public BoxSharedLink(String json) { this.setUnsharedDate(unshareDate); } } - BoxSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions, String password) { + BoxSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions, + String password) { this.setAccess(access); this.setPermissions(permissions); this.setPassword(password); diff --git a/src/main/java/com/box/sdk/BoxWebLink.java b/src/main/java/com/box/sdk/BoxWebLink.java index b8bb1929e..9522d511c 100644 --- a/src/main/java/com/box/sdk/BoxWebLink.java +++ b/src/main/java/com/box/sdk/BoxWebLink.java @@ -56,6 +56,15 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD return info.getSharedLink(); } + /** + * Creates new SharedLink for a BoxWebLink with a password. + * + * @param access The access level of the shared link. + * @param unshareDate A specified date to unshare the Box web link. + * @param permissions The permissions to set on the shared link for the Box web link. + * @param password Password set on the shared link to give access to the Box web link. + * @return information about the newly created shared link. + */ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions, String password) { diff --git a/src/test/Fixtures/BoxSharedLink/CreateSharedLink201.json b/src/test/Fixtures/BoxSharedLink/CreateSharedLink201.json new file mode 100644 index 000000000..5129998d4 --- /dev/null +++ b/src/test/Fixtures/BoxSharedLink/CreateSharedLink201.json @@ -0,0 +1,18 @@ +{ + "shared_link": { + "url": "https://testt3t2t2t2.box.com/s/12345", + "download_url": "https://testt3t2t2t2.box.com/shared/static/12345.png", + "vanity_url": null, + "effective_access": "open", + "effective_permission": "can_download", + "is_password_enabled": true, + "unshared_at": null, + "download_count": 0, + "preview_count": 0, + "access": "open", + "permissions": { + "can_preview": true, + "can_download": true + } + } +} diff --git a/src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json b/src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json deleted file mode 100644 index 9db6ec3b8..000000000 --- a/src/test/Fixtures/BoxSharedLink/CreateSharedLinkForFile201.json +++ /dev/null @@ -1,16 +0,0 @@ -"shared_link": { - "url": "https://testt3t2t2t2.box.com/s/12345", - "download_url": "https://testt3t2t2t2.box.com/shared/static/12345.png", - "vanity_url": null, - "effective_access": "open", - "effective_permission": "can_download", - "is_password_enabled": true, - "unshared_at": null, - "download_count": 0, - "preview_count": 0, - "access": "open", - "permissions": { - "can_preview": true, - "can_download": true - } -}, diff --git a/src/test/java/com/box/sdk/BoxFileTest.java b/src/test/java/com/box/sdk/BoxFileTest.java index ea9d360ad..10182f1b2 100644 --- a/src/test/java/com/box/sdk/BoxFileTest.java +++ b/src/test/java/com/box/sdk/BoxFileTest.java @@ -1401,13 +1401,19 @@ public void createSharedLinkSucceeds() throws IOException { final String password = "test1"; String result = ""; + JsonObject permissionsObject = new JsonObject() + .add("can_download", true) + .add("can_preview", true); + JsonObject innerObject = new JsonObject() - .add("password", password); + .add("password", password) + .add("access", "open") + .add("permissions", permissionsObject); JsonObject sharedLinkObject = new JsonObject() .add("shared_link", innerObject); - result = TestConfig.getFixture("BoxSharedLink/CreateSharedLinkForFile201"); + result = TestConfig.getFixture("BoxSharedLink/CreateSharedLink201"); WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) .withRequestBody(WireMock.equalToJson(sharedLinkObject.toString())) @@ -1422,56 +1428,9 @@ public void createSharedLinkSucceeds() throws IOException { permissions.setCanPreview(true); BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions, password); - Assert.assertEquals(true, sharedLink.getIsPasswordEnabled()); } - @Test - @Category(UnitTest.class) - public void createSharedLinkWithPasswordSucceeds() throws IOException { - final String fileID = "1111"; - final String password = "test1"; - String result = ""; - - JsonObject innerObject = new JsonObject() - .add("password", password); - - JsonObject sharedLinkObject = new JsonObject() - .add("shared_link", innerObject); - - result = TestConfig.getFixture("BoxFile/CreateSharedLinkWithPassword201"); - - WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) - .willReturn(WireMock.aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(200))); - - WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) - .willReturn(WireMock.aResponse() - .withHeader("Content-Type", "application/json") - .withBody(result))); - - WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID)) - .withRequestBody(WireMock.equalToJson(sharedLinkObject.toString())) - .willReturn(WireMock.aResponse() - .withHeader("Content-Type", "application/json") - .withBody(result))); - - BoxFile file = new BoxFile(this.api, fileID); - BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); - - permissions.setCanDownload(true); - permissions.setCanPreview(true); - BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions); - - sharedLink.setPassword(password); - BoxFile.Info info = file.new Info(); - info.setSharedLink(sharedLink); - file.updateInfo(info); - - Assert.assertEquals(true, info.getSharedLink().getIsPasswordEnabled()); - } - private BoxFile.Info parallelMuliputUpload(File file, BoxFolder folder, String fileName) throws IOException, InterruptedException { FileInputStream newStream = new FileInputStream(file); diff --git a/src/test/java/com/box/sdk/BoxFolderTest.java b/src/test/java/com/box/sdk/BoxFolderTest.java index 93938eec6..784ff1b8a 100644 --- a/src/test/java/com/box/sdk/BoxFolderTest.java +++ b/src/test/java/com/box/sdk/BoxFolderTest.java @@ -944,6 +944,44 @@ public void testGetAllMetadataSucceeds() throws IOException { Assert.assertEquals(scope, metadata.getScope()); } + @Test + @Category(UnitTest.class) + public void createSharedLinkSucceeds() throws IOException { + final String folderID = "1111"; + final String password = "test1"; + String result = ""; + + JsonObject permissionsObject = new JsonObject() + .add("can_download", true) + .add("can_preview", true); + + JsonObject innerObject = new JsonObject() + .add("password", password) + .add("access", "open") + .add("permissions", permissionsObject); + + JsonObject sharedLinkObject = new JsonObject() + .add("shared_link", innerObject); + + result = TestConfig.getFixture("BoxSharedLink/CreateSharedLink201"); + + WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/folders/" + folderID)) + .withRequestBody(WireMock.equalToJson(sharedLinkObject.toString())) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result))); + + BoxFolder folder = new BoxFolder(this.api, folderID); + BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); + + permissions.setCanDownload(true); + permissions.setCanPreview(true); + BoxSharedLink sharedLink = folder.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions, + password); + + Assert.assertEquals(true, sharedLink.getIsPasswordEnabled()); + } + private void getUploadSessionStatus(BoxFileUploadSession session) { BoxFileUploadSession.Info sessionInfo = session.getStatus(); Assert.assertNotNull(sessionInfo.getSessionExpiresAt()); diff --git a/src/test/java/com/box/sdk/BoxWebLinkTest.java b/src/test/java/com/box/sdk/BoxWebLinkTest.java index 8a1779661..5ee18cf79 100644 --- a/src/test/java/com/box/sdk/BoxWebLinkTest.java +++ b/src/test/java/com/box/sdk/BoxWebLinkTest.java @@ -257,4 +257,42 @@ public void testDeleteWebLinkSucceeds() throws IOException { BoxWebLink webLink = new BoxWebLink(this.api, webLinkID); webLink.delete(); } + + @Test + @Category(UnitTest.class) + public void createSharedLinkSucceeds() throws IOException { + final String webLinkID = "1111"; + final String password = "test1"; + String result = ""; + + JsonObject permissionsObject = new JsonObject() + .add("can_download", true) + .add("can_preview", true); + + JsonObject innerObject = new JsonObject() + .add("password", password) + .add("access", "open") + .add("permissions", permissionsObject); + + JsonObject sharedLinkObject = new JsonObject() + .add("shared_link", innerObject); + + result = TestConfig.getFixture("BoxSharedLink/CreateSharedLink201"); + + WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/web_links/" + webLinkID)) + .withRequestBody(WireMock.equalToJson(sharedLinkObject.toString())) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withBody(result))); + + BoxWebLink webLink = new BoxWebLink(this.api, webLinkID); + BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions(); + + permissions.setCanDownload(true); + permissions.setCanPreview(true); + BoxSharedLink sharedLink = webLink.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions, + password); + + Assert.assertEquals(true, sharedLink.getIsPasswordEnabled()); + } }