james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [james-project] 12/24: JAMES-2708 LocalFileSharing mechanism should be instanciable without configuration
Date Thu, 11 Apr 2019 00:33:43 GMT
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 246421a4442317b88fab06d1f3ea9de89d22b9df
Author: Benoit Tellier <btellier@linagora.com>
AuthorDate: Mon Apr 8 15:49:44 2019 +0700

    JAMES-2708 LocalFileSharing mechanism should be instanciable without configuration
    
    This is to avoid configuration changes upon migrations
---
 .../blob/export/file/LocalFileBlobExportMechanism.java |  6 +++---
 .../export/file/LocalFileBlobExportMechanismTest.java  | 18 ++++++++++++------
 .../modules/LocalFileBlobExportMechanismModule.java    |  6 +++++-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
b/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
index 67ceba6..32e899b 100644
--- a/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
+++ b/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
@@ -52,9 +52,9 @@ public class LocalFileBlobExportMechanism implements BlobExportMechanism
{
 
     public static class Configuration {
 
-        public static Configuration from(org.apache.commons.configuration.Configuration propertiesConfiguration)
{
-            String exportDirectory = propertiesConfiguration.getString(DIRECTORY_LOCATION_PROPERTY);
-            return new Configuration(exportDirectory);
+        public static Optional<Configuration> from(org.apache.commons.configuration.Configuration
propertiesConfiguration) {
+            String exportDirectory = propertiesConfiguration.getString(DIRECTORY_LOCATION_PROPERTY,
null);
+            return Optional.ofNullable(exportDirectory).map(Configuration::new);
         }
 
         private static final String DIRECTORY_LOCATION_PROPERTY = "blob.export.localFile.directory";
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 a1793bb..6e70cbd 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
@@ -191,21 +191,27 @@ class LocalFileBlobExportMechanismTest {
             });
     }
 
-        @Nested
+    @Nested
     class ConfigurationTest {
-
         @Test
         void shouldMatchBeanContract() {
             EqualsVerifier.forClass(Configuration.class)
                 .verify();
         }
+
+        @Test
+        void fromShouldReturnEmptyWhenDirectoryIsMissing() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+            assertThat(Configuration.from(configuration)).isEmpty();
+        }
+
         @Test
-        void fromShouldThrowWhenDirectoryIsMissing() {
+        void fromShouldReturnEmptyWhenDirectoryIsNull() {
             PropertiesConfiguration configuration = new PropertiesConfiguration();
             configuration.addProperty("blob.export.localFile.directory", null);
 
-            assertThatThrownBy(() -> Configuration.from(configuration))
-                .isInstanceOf(NullPointerException.class);
+            assertThat(Configuration.from(configuration)).isEmpty();
         }
 
         @Test
@@ -215,7 +221,7 @@ class LocalFileBlobExportMechanismTest {
             configuration.addProperty("blob.export.localFile.directory", exportDirectory);
 
             assertThat(Configuration.from(configuration))
-                .isEqualTo(new Configuration(exportDirectory));
+                .contains(new Configuration(exportDirectory));
         }
     }
 }
\ No newline at end of file
diff --git a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LocalFileBlobExportMechanismModule.java
b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LocalFileBlobExportMechanismModule.java
index 70995c8..7b2f046 100644
--- a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LocalFileBlobExportMechanismModule.java
+++ b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/LocalFileBlobExportMechanismModule.java
@@ -46,7 +46,11 @@ public class LocalFileBlobExportMechanismModule extends AbstractModule
{
     LocalFileBlobExportMechanism.Configuration localFileExportConfiguration(PropertiesProvider
propertiesProvider) throws ConfigurationException {
         try {
             Configuration configuration = propertiesProvider.getConfiguration(ConfigurationComponent.NAME);
-            return LocalFileBlobExportMechanism.Configuration.from(configuration);
+            return LocalFileBlobExportMechanism.Configuration.from(configuration)
+                .orElseGet(() -> {
+                    LOGGER.warn("Missing LocalFileBlobExportMechanism configuration, using
default localFile blob exporting configuration");
+                    return LocalFileBlobExportMechanism.Configuration.DEFAULT_CONFIGURATION;
+                });
         } catch (FileNotFoundException e) {
             LOGGER.warn("Could not find " + ConfigurationComponent.NAME + " configuration
file, using default localFile blob exporting configuration");
             return LocalFileBlobExportMechanism.Configuration.DEFAULT_CONFIGURATION;


---------------------------------------------------------------------
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