james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [james-project] 04/06: JAMES-2741 Refactor blob store tests with new save Strings methods
Date Mon, 29 Apr 2019 08:09:36 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 71dcff813541cb53ab3a5f76b375c19b65dab158
Author: Rene Cordier <rcordier@linagora.com>
AuthorDate: Mon Apr 22 16:16:53 2019 +0700

    JAMES-2741 Refactor blob store tests with new save Strings methods
---
 .../blob/cassandra/CassandraBlobsDAOTest.java      |  2 +-
 .../file/LocalFileBlobExportMechanismTest.java     |  6 ++---
 .../ObjectStorageBlobsDAOContract.java             |  8 +++----
 .../objectstorage/ObjectStorageBlobsDAOTest.java   | 27 +++++++++++++---------
 .../james/blob/union/UnionBlobStoreTest.java       | 20 +++++++++++++++-
 .../linshare/LinshareBlobExportMechanismTest.java  |  6 ++---
 6 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
index 3e570ee..9831bed 100644
--- a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
+++ b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
@@ -72,7 +72,7 @@ public class CassandraBlobsDAOTest implements MetricableBlobStoreContract
{
     @Test
     void readBytesShouldReturnSplitSavedDataByChunk() {
         String longString = Strings.repeat("0123456789\n", MULTIPLE_CHUNK_SIZE);
-        BlobId blobId = testee.save(longString.getBytes(StandardCharsets.UTF_8)).block();
+        BlobId blobId = testee.save(longString).block();
 
         byte[] bytes = testee.readBytes(blobId).block();
 
diff --git a/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanismTest.java
b/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanismTest.java
index 6e70cbd..2b91681 100644
--- a/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanismTest.java
+++ b/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanismTest.java
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.io.ByteArrayInputStream;
 import java.io.FileInputStream;
 import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
@@ -34,6 +33,7 @@ import javax.mail.internet.InternetAddress;
 
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
@@ -55,7 +55,7 @@ import nl.jqno.equalsverifier.EqualsVerifier;
 
 @ExtendWith(FileSystemExtension.class)
 class LocalFileBlobExportMechanismTest {
-    private static final byte[] BLOB_CONTENT = "blob_content".getBytes(StandardCharsets.UTF_8);
+    private static final String BLOB_CONTENT = "blob_content";
     private static final String JAMES_HOST = "james-host";
 
     private BlobStore blobStore;
@@ -124,7 +124,7 @@ class LocalFileBlobExportMechanismTest {
                 try {
                     String absoluteUrl = sentMail.getMsg().getHeader(LocalFileBlobExportMechanism.CORRESPONDING_FILE_HEADER)[0];
 
-                    assertThat(new FileInputStream(absoluteUrl)).hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
+                    assertThat(new FileInputStream(absoluteUrl)).hasSameContentAs(IOUtils.toInputStream(BLOB_CONTENT,
StandardCharsets.UTF_8));
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
index 409272d..cada68c 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
@@ -21,16 +21,16 @@ package org.apache.james.blob.objectstorage;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.james.blob.api.BlobId;
 
 
 public interface ObjectStorageBlobsDAOContract {
 
-    byte[] BYTES = "content".getBytes(StandardCharsets.UTF_8);
+    String CONTENT = "content";
 
     ContainerName containerName();
 
@@ -38,9 +38,9 @@ public interface ObjectStorageBlobsDAOContract {
         ObjectStorageBlobsDAO dao = builder.build();
         dao.createContainer(containerName()).block();
 
-        BlobId blobId = dao.save(BYTES).block();
+        BlobId blobId = dao.save(CONTENT).block();
 
         InputStream inputStream = dao.read(blobId);
-        assertThat(inputStream).hasSameContentAs(new ByteArrayInputStream(BYTES));
+        assertThat(inputStream).hasSameContentAs(IOUtils.toInputStream(CONTENT, StandardCharsets.UTF_8));
     }
 }
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
index 63ebb7d..b1ec0c4 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
@@ -49,6 +49,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Strings;
+
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
 
@@ -133,12 +134,10 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract
{
             .payloadCodec(new AESPayloadCodec(CRYPTO_CONFIG))
             .build();
         String content = "James is the best!";
-        byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
-        BlobId blobId = encryptedDao.save(bytes).block();
+        BlobId blobId = encryptedDao.save(content).block();
 
         InputStream read = encryptedDao.read(blobId);
-        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
-        String expectedContent = IOUtils.toString(inputStream, Charsets.UTF_8);
+        String expectedContent = IOUtils.toString(read, Charsets.UTF_8);
         assertThat(content).isEqualTo(expectedContent);
     }
 
@@ -151,17 +150,15 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract
{
             .payloadCodec(new AESPayloadCodec(CRYPTO_CONFIG))
             .build();
         String content = "James is the best!";
-        byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
-        BlobId blobId = encryptedDao.save(bytes).block();
+        BlobId blobId = encryptedDao.save(content).block();
 
         InputStream encryptedIs = testee.read(blobId);
         assertThat(encryptedIs).isNotNull();
-        byte[] encryptedBytes = IOUtils.toByteArray(encryptedIs);
-        assertThat(encryptedBytes).isNotEqualTo(bytes);
+        String encryptedString = IOUtils.toString(encryptedIs, Charsets.UTF_8);
+        assertThat(encryptedString).isNotEqualTo(content);
 
         InputStream clearTextIs = encryptedDao.read(blobId);
-        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
-        String expectedContent = IOUtils.toString(inputStream, Charsets.UTF_8);
+        String expectedContent = IOUtils.toString(clearTextIs, Charsets.UTF_8);
         assertThat(content).isEqualTo(expectedContent);
     }
 
@@ -182,6 +179,14 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract
{
     }
 
     @Test
+    void saveStringShouldNotCompleteWhenDoesNotAwait() {
+        Mono<BlobId> blobIdFuture = testee
+            .save(BIG_STRING)
+            .subscribeOn(Schedulers.elastic());
+        assertThat(blobIdFuture.toFuture()).isNotCompleted();
+    }
+
+    @Test
     void saveInputStreamShouldNotCompleteWhenDoesNotAwait() {
         Mono<BlobId> blobIdFuture = testee
             .save(new ByteArrayInputStream(BIG_STRING.getBytes(StandardCharsets.UTF_8)),
BIG_STRING.length())
@@ -191,7 +196,7 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract
{
 
     @Test
     void readBytesShouldNotCompleteWhenDoesNotAwait() {
-        BlobId blobId = testee().save(BIG_STRING.getBytes(StandardCharsets.UTF_8)).block();
+        BlobId blobId = testee().save(BIG_STRING).block();
         Mono<byte[]> resultFuture = testee.readBytes(blobId).subscribeOn(Schedulers.elastic());
         assertThat(resultFuture.toFuture()).isNotCompleted();
     }
diff --git a/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
b/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
index f2f875e..d567a94 100644
--- a/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
+++ b/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
@@ -122,7 +122,8 @@ class UnionBlobStoreTest implements BlobStoreContract {
     }
 
     private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory();
-    private static final byte [] BLOB_CONTENT = "blob content".getBytes();
+    private static final String STRING_CONTENT = "blob content";
+    private static final byte [] BLOB_CONTENT = STRING_CONTENT.getBytes();
 
     private MemoryBlobStore currentBlobStore;
     private MemoryBlobStore legacyBlobStore;
@@ -295,6 +296,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
         Stream<Function<UnionBlobStore, Mono<?>>> blobStoreOperationsReturnFutures()
{
             return Stream.of(
                 blobStore -> blobStore.save(BLOB_CONTENT),
+                blobStore -> blobStore.save(STRING_CONTENT),
                 blobStore -> blobStore.save(new ByteArrayInputStream(BLOB_CONTENT), BLOB_CONTENT.length),
                 blobStore -> blobStore.readBytes(BLOB_ID_FACTORY.randomId()));
         }
@@ -404,6 +406,22 @@ class UnionBlobStoreTest implements BlobStoreContract {
     }
 
     @Test
+    void saveStringShouldWriteToCurrent() {
+        BlobId blobId = unionBlobStore.save(STRING_CONTENT).block();
+
+        assertThat(currentBlobStore.readBytes(blobId).block())
+            .isEqualTo(BLOB_CONTENT);
+    }
+
+    @Test
+    void saveStringShouldNotWriteToLegacy() {
+        BlobId blobId = unionBlobStore.save(STRING_CONTENT).block();
+
+        assertThatThrownBy(() -> legacyBlobStore.readBytes(blobId).block())
+            .isInstanceOf(ObjectStoreException.class);
+    }
+
+    @Test
     void saveInputStreamShouldWriteToCurrent() {
         BlobId blobId = unionBlobStore.save(new ByteArrayInputStream(BLOB_CONTENT), BLOB_CONTENT.length).block();
 
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 569cde9..db04467 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,8 +28,6 @@ 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;
@@ -67,7 +65,7 @@ class LinshareBlobExportMechanismTest {
 
     @Test
     void exportShouldShareTheDocumentViaLinShare() throws Exception {
-        BlobId blobId = blobStore.save("content".getBytes(StandardCharsets.UTF_8)).block();
+        BlobId blobId = blobStore.save("content").block();
 
         testee.blobId(blobId)
             .with(new MailAddress(USER_2.getUsername()))
@@ -86,7 +84,7 @@ class LinshareBlobExportMechanismTest {
 
     @Test
     void exportShouldSendAnEmailToSharee() throws Exception {
-        BlobId blobId = blobStore.save("content".getBytes(StandardCharsets.UTF_8)).block();
+        BlobId blobId = blobStore.save("content").block();
 
         testee.blobId(blobId)
             .with(new MailAddress(USER_2.getUsername()))


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


Mime
View raw message