You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/05/10 11:30:15 UTC

[james-project] 02/17: JAMES-2712 Add unit tests for Linshare download file API

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit cbba47625040ecc60513eac9db83c58cb79f3cd4
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue May 7 17:03:27 2019 +0700

    JAMES-2712 Add unit tests for Linshare download file API
---
 .../linshare/LinshareBlobExportMechanismTest.java  | 23 ++++++++++++++++++++--
 .../james/linshare/client/LinshareAPITest.java     | 19 ++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareBlobExportMechanismTest.java b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareBlobExportMechanismTest.java
index db04467..fa7e1c3 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareBlobExportMechanismTest.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareBlobExportMechanismTest.java
@@ -28,12 +28,15 @@ import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.hasItem;
 import static org.hamcrest.Matchers.hasSize;
 
+import java.nio.charset.StandardCharsets;
+
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.export.api.BlobExportMechanism;
 import org.apache.james.blob.export.api.FileExtension;
 import org.apache.james.blob.memory.MemoryBlobStore;
 import org.apache.james.core.MailAddress;
+import org.apache.james.linshare.client.Document;
 import org.apache.james.linshare.client.LinshareAPI;
 import org.awaitility.Awaitility;
 import org.awaitility.Duration;
@@ -52,6 +55,7 @@ class LinshareBlobExportMechanismTest {
     private MemoryBlobStore blobStore;
     private LinshareBlobExportMechanism testee;
     private HashBlobId.Factory blobIdFactory;
+    private LinshareAPI user2API;
 
     @BeforeEach
     void setUp() throws Exception {
@@ -61,6 +65,8 @@ class LinshareBlobExportMechanismTest {
         testee = new LinshareBlobExportMechanism(
             linshareExtension.getAPIFor(USER_1),
             blobStore);
+
+        user2API = linshareExtension.getAPIFor(USER_2);
     }
 
     @Test
@@ -73,8 +79,6 @@ class LinshareBlobExportMechanismTest {
             .fileExtension(FileExtension.of("txt"))
             .export();
 
-        LinshareAPI user2API = linshareExtension.getAPIFor(USER_2);
-
         assertThat(user2API.receivedShares())
             .hasSize(1)
             .allSatisfy(receivedShare -> assertThat(receivedShare.getDocument().getName()).endsWith(".txt"))
@@ -111,6 +115,21 @@ class LinshareBlobExportMechanismTest {
     }
 
     @Test
+    void exportShouldShareTheDocumentAndAllowDownloadViaLinShare() throws Exception {
+        BlobId blobId = blobStore.save("content").block();
+
+        testee.blobId(blobId)
+            .with(new MailAddress(USER_2.getUsername()))
+            .explanation(EXPLANATION)
+            .fileExtension(FileExtension.of("txt"))
+            .export();
+
+        Document sharedDoc = user2API.receivedShares().get(0).getDocument();
+        byte[] sharedFile =  linshareExtension.downloadSharedFile(USER_2, sharedDoc.getId(), sharedDoc.getName());
+        assertThat(sharedFile).isEqualTo("content".getBytes(StandardCharsets.UTF_8));
+    }
+
+    @Test
     void exportShouldFailWhenBlobDoesNotExist() {
         BlobId blobId = blobIdFactory.randomId();
 
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/client/LinshareAPITest.java b/third-party/linshare/src/test/java/org/apache/james/linshare/client/LinshareAPITest.java
index d765379..85bc8d9 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/client/LinshareAPITest.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/client/LinshareAPITest.java
@@ -34,6 +34,7 @@ import java.nio.file.Files;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.james.core.MailAddress;
 import org.apache.james.linshare.LinshareExtension;
 import org.assertj.core.api.SoftAssertions;
@@ -232,6 +233,24 @@ class LinshareAPITest {
             });
     }
 
+    @Test
+    void downloadShareShouldGetUploadedSharedFile() throws Exception {
+        File user1File = templateFile();
+        Document user1Document = user1LinshareAPI.uploadDocument(user1File);
+
+        ShareRequest shareRequest = ShareRequest.builder()
+            .message(MESSAGE)
+            .addDocumentId(user1Document.getId())
+            .addRecipient(new MailAddress(USER_2.getUsername()))
+            .build();
+
+        user1LinshareAPI.share(shareRequest);
+        Document sharedDoc = user2LinshareAPI.receivedShares().get(0).getDocument();
+
+        byte[] sharedFile =  linshareExtension.downloadSharedFile(USER_2, sharedDoc.getId(), sharedDoc.getName());
+        assertThat(sharedFile).isEqualTo(FileUtils.readFileToByteArray(user1File));
+    }
+
     private File templateFile() throws Exception {
         return Files.createTempFile("linshare-api-test", ".temp").toFile();
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org