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/06/10 04:15:55 UTC
[james-project] 02/06: JAMES-2782 A component to generate exported
file names
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 4a2ec3a19e9a5b5ae38294270baa6d4810655d3d
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Jun 6 17:28:53 2019 +0700
JAMES-2782 A component to generate exported file names
And will be used by LocalFileExport & LinshareExport mechanism
---
server/blob/blob-export-api/pom.xml | 6 ++
.../export/api/ExportedFileNamesGenerator.java | 43 ++++++++++++
.../export/api/ExportedFileNamesGeneratorTest.java | 79 ++++++++++++++++++++++
3 files changed, 128 insertions(+)
diff --git a/server/blob/blob-export-api/pom.xml b/server/blob/blob-export-api/pom.xml
index a3336bd..408d522 100644
--- a/server/blob/blob-export-api/pom.xml
+++ b/server/blob/blob-export-api/pom.xml
@@ -42,6 +42,12 @@
<artifactId>blob-api</artifactId>
</dependency>
<dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>blob-api</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
diff --git a/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/ExportedFileNamesGenerator.java b/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/ExportedFileNamesGenerator.java
new file mode 100644
index 0000000..501196b
--- /dev/null
+++ b/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/ExportedFileNamesGenerator.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.export.api;
+
+import java.util.Optional;
+
+import org.apache.james.blob.api.BlobId;
+
+import com.google.common.base.Preconditions;
+
+public interface ExportedFileNamesGenerator {
+
+ static String generateFileName(Optional<String> fileCustomPrefix,
+ BlobId blobId,
+ Optional<FileExtension> fileExtension) {
+ Preconditions.checkNotNull(blobId);
+
+ String fileNameWithPrefix = fileCustomPrefix
+ .map(prefix -> prefix + blobId.asString())
+ .orElse(blobId.asString());
+
+ return fileExtension
+ .map(extension -> extension.appendExtension(fileNameWithPrefix))
+ .orElse(fileNameWithPrefix);
+ }
+}
diff --git a/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/ExportedFileNamesGeneratorTest.java b/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/ExportedFileNamesGeneratorTest.java
new file mode 100644
index 0000000..35cfb1f
--- /dev/null
+++ b/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/ExportedFileNamesGeneratorTest.java
@@ -0,0 +1,79 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.export.api;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Optional;
+
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.TestBlobId;
+import org.junit.jupiter.api.Test;
+
+class ExportedFileNamesGeneratorTest {
+
+ private static final TestBlobId.Factory BLOB_ID_FACTORY = new TestBlobId.Factory();
+ private static final BlobId BLOB_ID = BLOB_ID_FACTORY.from("blobId");
+
+ @Test
+ void generateFileNameShouldNotHavePrefixWhenEmptyPrefix() {
+ Optional<String> prefix = Optional.empty();
+ Optional<FileExtension> extension = Optional.of(FileExtension.ZIP);
+
+ assertThat(ExportedFileNamesGenerator.generateFileName(prefix, BLOB_ID, extension))
+ .isEqualTo("blobId.zip");
+ }
+
+ @Test
+ void generateFileNameShouldNotHaveSuffixWhenEmptySuffix() {
+ Optional<FileExtension> extension = Optional.empty();
+
+ assertThat(ExportedFileNamesGenerator.generateFileName(Optional.of("prefix-"), BLOB_ID, extension))
+ .isEqualTo("prefix-blobId");
+ }
+
+ @Test
+ void generateFileNameShouldNotHaveSuffixAndPrefixWhenNotSpecifying() {
+ Optional<String> prefix = Optional.empty();
+ Optional<FileExtension> extension = Optional.empty();
+
+ assertThat(ExportedFileNamesGenerator.generateFileName(prefix, BLOB_ID, extension))
+ .isEqualTo("blobId");
+ }
+
+ @Test
+ void generateFileNameShouldHaveSuffixAndPrefixWhenSpecified() {
+ Optional<FileExtension> extension = Optional.of(FileExtension.ZIP);
+
+ assertThat(ExportedFileNamesGenerator.generateFileName(Optional.of("prefix-"), BLOB_ID, extension))
+ .isEqualTo("prefix-blobId.zip");
+ }
+
+ @Test
+ void generateFileNameShouldThrowWhenNullBlobId() {
+ BlobId nullBlobId = null;
+ assertThatThrownBy(() -> ExportedFileNamesGenerator.generateFileName(
+ Optional.empty(),
+ nullBlobId,
+ Optional.empty()))
+ .isInstanceOf(NullPointerException.class);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org