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 f58bfd83e95a52a8e10b234caf78fcdce8d4ed0a Author: Rene Cordier <[email protected]> AuthorDate: Thu Apr 18 17:54:55 2019 +0700 JAMES-2741 Add save(String) tests in BlobStore contract --- .../apache/james/blob/api/BlobStoreContract.java | 25 +++++++++++++++++++++- .../blob/api/MetricableBlobStoreContract.java | 13 +++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java index 6983485..dbb9863 100644 --- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java +++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java @@ -32,8 +32,9 @@ import com.google.common.base.Strings; public interface BlobStoreContract { + String SHORT_STRING = "toto"; byte[] EMPTY_BYTEARRAY = {}; - byte[] SHORT_BYTEARRAY = "toto".getBytes(StandardCharsets.UTF_8); + byte[] SHORT_BYTEARRAY = SHORT_STRING.getBytes(StandardCharsets.UTF_8); byte[] ELEVEN_KILOBYTES = Strings.repeat("0123456789\n", 1000).getBytes(StandardCharsets.UTF_8); byte[] TWELVE_MEGABYTES = Strings.repeat("0123456789\r\n", 1024 * 1024).getBytes(StandardCharsets.UTF_8); @@ -48,6 +49,12 @@ public interface BlobStoreContract { } @Test + default void saveShouldThrowWhenNullString() { + assertThatThrownBy(() -> testee().save((String) null).block()) + .isInstanceOf(NullPointerException.class); + } + + @Test default void saveShouldThrowWhenNullInputStream() { assertThatThrownBy(() -> testee().save((InputStream) null, 0).block()) .isInstanceOf(NullPointerException.class); @@ -63,6 +70,15 @@ public interface BlobStoreContract { } @Test + default void saveShouldSaveEmptyString() { + BlobId blobId = testee().save(new String()).block(); + + byte[] bytes = testee().readBytes(blobId).block(); + + assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty(); + } + + @Test default void saveShouldSaveEmptyInputStream() { BlobId blobId = testee().save(new ByteArrayInputStream(EMPTY_BYTEARRAY), EMPTY_BYTEARRAY.length).block(); @@ -79,6 +95,13 @@ public interface BlobStoreContract { } @Test + default void saveShouldReturnBlobIdOfString() { + BlobId blobId = testee().save(SHORT_STRING).block(); + + assertThat(blobId).isEqualTo(blobIdFactory().from("31f7a65e315586ac198bd798b6629ce4903d0899476d5741a9f32e2e521b6a66")); + } + + @Test default void saveShouldReturnBlobIdOfInputStream() { BlobId blobId = testee().save(new ByteArrayInputStream(SHORT_BYTEARRAY), SHORT_BYTEARRAY.length).block(); diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java index 9b8cfb5..7ed9b7e 100644 --- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java +++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java @@ -27,7 +27,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; -import java.time.Duration; import org.apache.james.metrics.tests.RecordingMetricFactory; import org.junit.jupiter.api.Test; @@ -53,7 +52,8 @@ public interface MetricableBlobStoreContract extends BlobStoreContract { @RegisterExtension MetricableBlobStoreExtension metricsTestExtension = new MetricableBlobStoreExtension(); - byte[] BYTES_CONTENT = "bytes content".getBytes(StandardCharsets.UTF_8); + String STRING_CONTENT = "blob content"; + byte[] BYTES_CONTENT = STRING_CONTENT.getBytes(StandardCharsets.UTF_8); @Test default void saveBytesShouldPublishSaveBytesTimerMetrics() { @@ -65,6 +65,15 @@ public interface MetricableBlobStoreContract extends BlobStoreContract { } @Test + default void saveStringShouldPublishSaveBytesTimerMetrics() { + testee().save(STRING_CONTENT).block(); + testee().save(STRING_CONTENT).block(); + + assertThat(metricsTestExtension.getMetricFactory().executionTimesFor(SAVE_BYTES_TIMER_NAME)) + .hasSize(2); + } + + @Test default void saveInputStreamShouldPublishSaveInputStreamTimerMetrics() { testee().save(new ByteArrayInputStream(BYTES_CONTENT), BYTES_CONTENT.length).block(); testee().save(new ByteArrayInputStream(BYTES_CONTENT), BYTES_CONTENT.length).block(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
