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/04/11 00:33:39 UTC
[james-project] 08/24: JAMES-2688 BlobExport Guice module: choosing
impl from configurations
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 5e78a27d83cd6f7075d7d0072ddebd4a7b3ac26a
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Mar 27 16:48:44 2019 +0700
JAMES-2688 BlobExport Guice module: choosing impl from configurations
---
.../export/file/LocalFileBlobExportMechanism.java | 10 +--
.../blob/export/file/FileSystemExtension.java | 6 ++
.../blob/export/file/FileSystemExtensionTest.java | 64 ++++++++++++++
.../file/LocalFileBlobExportMechanismTest.java | 6 +-
server/container/guice/blob-export-guice/pom.xml | 29 +++++++
.../apache/james/modules/BlobExportImplChoice.java | 13 ++-
.../james/modules/BlobExportMechanismModule.java | 73 ++++++++++++++++
.../LocalFileBlobExportMechanismModule.java | 28 +++++--
.../james/modules/BlobExportImplChoiceTest.java | 19 +++--
.../modules/BlobExportMechanismModuleTest.java | 98 ++++++++++++++++++++++
.../org/apache/james/CassandraJamesServerMain.java | 13 +--
.../org/apache/james/MemoryJamesServerMain.java | 4 +-
12 files changed, 325 insertions(+), 38 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 347ed7d..67ceba6 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
@@ -54,21 +54,17 @@ public class LocalFileBlobExportMechanism implements BlobExportMechanism {
public static Configuration from(org.apache.commons.configuration.Configuration propertiesConfiguration) {
String exportDirectory = propertiesConfiguration.getString(DIRECTORY_LOCATION_PROPERTY);
- return of(exportDirectory);
- }
-
- @VisibleForTesting
- static Configuration of(String exportDirectory) {
return new Configuration(exportDirectory);
}
- private static final String DIRECTORY_LOCATION_PROPERTY = "blob.export.localFile.storingDirectory";
+ private static final String DIRECTORY_LOCATION_PROPERTY = "blob.export.localFile.directory";
private static final String DEFAULT_DIRECTORY_LOCATION = "file://var/blobExporting";
public static final Configuration DEFAULT_CONFIGURATION = new Configuration(DEFAULT_DIRECTORY_LOCATION);
private final String exportDirectory;
- public Configuration(String exportDirectory) {
+ @VisibleForTesting
+ Configuration(String exportDirectory) {
Preconditions.checkNotNull(exportDirectory);
this.exportDirectory = exportDirectory;
diff --git a/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtension.java b/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtension.java
index 80410b3..34c3ad8 100644
--- a/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtension.java
+++ b/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtension.java
@@ -32,6 +32,8 @@ import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;
+import com.google.common.annotations.VisibleForTesting;
+
public class FileSystemExtension implements ParameterResolver, BeforeAllCallback, AfterAllCallback {
private FileSystemImpl fileSystem;
@@ -58,4 +60,8 @@ public class FileSystemExtension implements ParameterResolver, BeforeAllCallback
return fileSystem;
}
+ @VisibleForTesting
+ FileSystemImpl getFileSystem() {
+ return fileSystem;
+ }
}
diff --git a/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtensionTest.java b/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtensionTest.java
new file mode 100644
index 0000000..aef22d9
--- /dev/null
+++ b/server/blob/blob-export-file/src/test/java/org/apache/james/blob/export/file/FileSystemExtensionTest.java
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.file;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class FileSystemExtensionTest {
+
+ private static ExtensionContext DUMMY_EXTENSION_CONTEXT = null;
+
+ @RegisterExtension
+ static FileSystemExtension fileSystemExtension = new FileSystemExtension();
+
+ @Nested
+ class DeletingFileSystemBaseDir {
+
+ @Test
+ void extensionShouldDeleteWhenTestDoesntCreateNewFiles() throws Exception {
+ fileSystemExtension.afterAll(DUMMY_EXTENSION_CONTEXT);
+
+ assertThat(fileSystemExtension.getFileSystem().getBasedir())
+ .doesNotExist();
+ }
+
+ @Test
+ void extensionShouldDeleteWhenTestCreateNewFiles() throws Exception {
+ File baseDir = fileSystemExtension.getFileSystem().getBasedir();
+ FileUtils.forceMkdir(baseDir);
+
+ File fileInsideBaseDir = new File(baseDir.getPath() + "/fileInsideBaseDir.temp");
+ FileUtils.touch(fileInsideBaseDir);
+
+ fileSystemExtension.afterAll(DUMMY_EXTENSION_CONTEXT);
+
+ assertThat(fileSystemExtension.getFileSystem().getBasedir())
+ .doesNotExist();
+ }
+ }
+}
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 e33c025..a1793bb 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
@@ -202,7 +202,7 @@ class LocalFileBlobExportMechanismTest {
@Test
void fromShouldThrowWhenDirectoryIsMissing() {
PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.addProperty("blob.export.localFile.storingDirectory", null);
+ configuration.addProperty("blob.export.localFile.directory", null);
assertThatThrownBy(() -> Configuration.from(configuration))
.isInstanceOf(NullPointerException.class);
@@ -212,10 +212,10 @@ class LocalFileBlobExportMechanismTest {
void fromShouldReturnConfigurationWhenDirectoryIsSpecified() {
PropertiesConfiguration configuration = new PropertiesConfiguration();
String exportDirectory = "file://var/localFileBlobExport";
- configuration.addProperty("blob.export.localFile.storingDirectory", exportDirectory);
+ configuration.addProperty("blob.export.localFile.directory", exportDirectory);
assertThat(Configuration.from(configuration))
- .isEqualTo(Configuration.of(exportDirectory));
+ .isEqualTo(new Configuration(exportDirectory));
}
}
}
\ No newline at end of file
diff --git a/server/container/guice/blob-export-guice/pom.xml b/server/container/guice/blob-export-guice/pom.xml
index 29a358b..c465ffc 100644
--- a/server/container/guice/blob-export-guice/pom.xml
+++ b/server/container/guice/blob-export-guice/pom.xml
@@ -36,6 +36,10 @@
<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>blob-api-guice</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>blob-export-api</artifactId>
</dependency>
<dependency>
@@ -46,5 +50,30 @@
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
</dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>james-server-guice-common</artifactId>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>nl.jqno.equalsverifier</groupId>
+ <artifactId>equalsverifier</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
index a28e622..90f6c35 100644
--- a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
+++ b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportImplChoice.java
@@ -19,12 +19,12 @@
package org.apache.james.modules;
-import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import com.github.steveash.guavate.Guavate;
import com.google.common.base.Joiner;
@@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableList;
class BlobExportImplChoice {
enum BlobExportImplName {
- LOCAL_FILE("localfile");
+ LOCAL_FILE("localFile");
private static Optional<BlobExportImplName> from(String implNameString) {
Preconditions.checkNotNull(implNameString);
@@ -65,21 +65,20 @@ class BlobExportImplChoice {
return new BlobExportImplChoice(BlobExportImplName.LOCAL_FILE);
}
- static BlobExportImplChoice from(Configuration configuration) {
+ static BlobExportImplChoice from(Configuration configuration) throws ConfigurationException {
String blobExportImpl = configuration.getString(BLOB_EXPORT_MECHANISM_IMPL);
String sanitizedImplName = Optional.ofNullable(blobExportImpl)
.map(String::trim)
- .map(implName -> implName.toLowerCase(Locale.US))
- .orElseThrow(() -> new NullPointerException(BLOB_EXPORT_MECHANISM_IMPL + " property is mandatory"));
+ .orElseThrow(() -> new ConfigurationException(BLOB_EXPORT_MECHANISM_IMPL + " property is mandatory"));
return BlobExportImplName.from(sanitizedImplName)
.map(BlobExportImplChoice::new)
- .orElseThrow(() -> new IllegalArgumentException(unknownBlobExportErrorMessage(blobExportImpl)));
+ .orElseThrow(() -> new ConfigurationException(unknownBlobExportErrorMessage(blobExportImpl)));
}
private static String unknownBlobExportErrorMessage(String blobExportImpl) {
- return String.format("unknow blob export mechanism '%s', please chose one in supported implementations(%s)",
+ return String.format("unknown blob export mechanism '%s', please choose one in supported implementations(%s)",
blobExportImpl,
Joiner.on(",").join(BlobExportImplName.plainImplNames()));
}
diff --git a/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java
new file mode 100644
index 0000000..5c9fba5
--- /dev/null
+++ b/server/container/guice/blob-export-guice/src/main/java/org/apache/james/modules/BlobExportMechanismModule.java
@@ -0,0 +1,73 @@
+/****************************************************************
+ * 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.modules;
+
+import java.io.FileNotFoundException;
+
+import javax.inject.Singleton;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.blob.export.api.BlobExportMechanism;
+import org.apache.james.blob.export.file.LocalFileBlobExportMechanism;
+import org.apache.james.modules.mailbox.ConfigurationComponent;
+import org.apache.james.utils.PropertiesProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provider;
+import com.google.inject.Provides;
+
+public class BlobExportMechanismModule extends AbstractModule {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(BlobExportMechanismModule.class);
+
+ @Override
+ protected void configure() {
+ install(new LocalFileBlobExportMechanismModule());
+ }
+
+ @VisibleForTesting
+ @Provides
+ @Singleton
+ BlobExportImplChoice provideChoice(PropertiesProvider propertiesProvider) throws ConfigurationException {
+ try {
+ Configuration configuration = propertiesProvider.getConfiguration(ConfigurationComponent.NAME);
+ return BlobExportImplChoice.from(configuration);
+ } catch (FileNotFoundException e) {
+ LOGGER.warn("Could not find " + ConfigurationComponent.NAME + " configuration file, using localFile blob exporting as the default");
+ return BlobExportImplChoice.localFile();
+ }
+ }
+
+ @VisibleForTesting
+ @Provides
+ @Singleton
+ BlobExportMechanism provideMechanism(BlobExportImplChoice implChoice, Provider<LocalFileBlobExportMechanism> localFileMechanismProvider) {
+ switch (implChoice.getImpl()) {
+ case LOCAL_FILE:
+ return localFileMechanismProvider.get();
+ default:
+ throw new RuntimeException("blobExportMechanism '" + implChoice.getImpl().getImplName() + "' is not supported yet");
+ }
+ }
+}
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 7d38201..70995c8 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
@@ -19,19 +19,37 @@
package org.apache.james.modules;
-import org.apache.james.blob.export.api.BlobExportMechanism;
+import java.io.FileNotFoundException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.blob.export.file.LocalFileBlobExportMechanism;
+import org.apache.james.modules.mailbox.ConfigurationComponent;
+import org.apache.james.utils.PropertiesProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.inject.AbstractModule;
-import com.google.inject.Scopes;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
public class LocalFileBlobExportMechanismModule extends AbstractModule {
+ private static final Logger LOGGER = LoggerFactory.getLogger(LocalFileBlobExportMechanismModule.class);
+
@Override
protected void configure() {
- bind(LocalFileBlobExportMechanism.Configuration.class).toInstance(LocalFileBlobExportMechanism.Configuration.DEFAULT_CONFIGURATION);
+ }
- bind(LocalFileBlobExportMechanism.class).in(Scopes.SINGLETON);
- bind(BlobExportMechanism.class).to(LocalFileBlobExportMechanism.class);
+ @Singleton
+ @Provides
+ LocalFileBlobExportMechanism.Configuration localFileExportConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
+ try {
+ Configuration configuration = propertiesProvider.getConfiguration(ConfigurationComponent.NAME);
+ return LocalFileBlobExportMechanism.Configuration.from(configuration);
+ } catch (FileNotFoundException e) {
+ LOGGER.warn("Could not find " + ConfigurationComponent.NAME + " configuration file, using default localFile blob exporting configuration");
+ return LocalFileBlobExportMechanism.Configuration.DEFAULT_CONFIGURATION;
+ }
}
}
diff --git a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportImplChoiceTest.java b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportImplChoiceTest.java
index e3a2c98..bb0ed2a 100644
--- a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportImplChoiceTest.java
+++ b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportImplChoiceTest.java
@@ -22,6 +22,7 @@ package org.apache.james.modules;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.james.modules.BlobExportImplChoice.BlobExportImplName;
import org.junit.jupiter.api.Test;
@@ -41,7 +42,7 @@ class BlobExportImplChoiceTest {
PropertiesConfiguration configuration = new PropertiesConfiguration();
assertThatThrownBy(() -> BlobExportImplChoice.from(configuration))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(ConfigurationException.class);
}
@Test
@@ -50,31 +51,31 @@ class BlobExportImplChoiceTest {
configuration.addProperty("blob.export.implementation", "unknown");
assertThatThrownBy(() -> BlobExportImplChoice.from(configuration))
- .isInstanceOf(IllegalArgumentException.class);
+ .isInstanceOf(ConfigurationException.class);
}
@Test
- void fromShouldReturnLocalFileImplWhenPassingLocalFileImplConfiguration() {
+ void fromShouldReturnLocalFileImplWhenPassingLocalFileImplConfiguration() throws Exception {
PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.addProperty("blob.export.implementation", "localfile");
+ configuration.addProperty("blob.export.implementation", "localFile");
assertThat(BlobExportImplChoice.from(configuration).getImpl())
.isEqualTo(BlobExportImplName.LOCAL_FILE);
}
@Test
- void fromShouldBeCaseInSensitive() {
+ void fromShouldThrowWhenCaseInSensitive() throws Exception {
PropertiesConfiguration configuration = new PropertiesConfiguration();
configuration.addProperty("blob.export.implementation", "localFILE");
- assertThat(BlobExportImplChoice.from(configuration).getImpl())
- .isEqualTo(BlobExportImplName.LOCAL_FILE);
+ assertThatThrownBy(() -> BlobExportImplChoice.from(configuration))
+ .isInstanceOf(ConfigurationException.class);
}
@Test
- void fromShouldIgnoreBlankSpacesBeforeAndAfter() {
+ void fromShouldIgnoreBlankSpacesBeforeAndAfter() throws Exception {
PropertiesConfiguration configuration = new PropertiesConfiguration();
- configuration.addProperty("blob.export.implementation", " localfile ");
+ configuration.addProperty("blob.export.implementation", " localFile ");
assertThat(BlobExportImplChoice.from(configuration).getImpl())
.isEqualTo(BlobExportImplName.LOCAL_FILE);
diff --git a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java
new file mode 100644
index 0000000..e69e608
--- /dev/null
+++ b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/BlobExportMechanismModuleTest.java
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.modules;
+
+import static org.apache.james.modules.mailbox.ConfigurationComponent.NAME;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.FakePropertiesProvider;
+import org.apache.james.blob.export.file.LocalFileBlobExportMechanism;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.google.inject.Provider;
+
+class BlobExportMechanismModuleTest {
+
+ private static LocalFileBlobExportMechanism LOCAL_FILE_EXPORT = mock(LocalFileBlobExportMechanism.class);
+ private static Provider<LocalFileBlobExportMechanism> LOCAL_FILE_EXPORT_PROVIDER = () -> LOCAL_FILE_EXPORT;
+
+ private BlobExportMechanismModule module;
+
+ @BeforeEach
+ void beforeEach() {
+ module = new BlobExportMechanismModule();
+ }
+
+ @Test
+ void provideChoiceShouldReturnLocalFileWhenConfigurationNotFound() throws Exception {
+ FakePropertiesProvider noConfigurationFile = FakePropertiesProvider.builder().build();
+
+ assertThat(module.provideChoice(noConfigurationFile))
+ .isEqualTo(BlobExportImplChoice.localFile());
+ }
+
+ @Test
+ void provideChoiceShouldReturnLocalFileWhenLocalFile() throws Exception {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("blob.export.implementation", "localFile");
+
+ FakePropertiesProvider noConfigurationFile = FakePropertiesProvider.builder()
+ .register(NAME, configuration)
+ .build();
+
+ assertThat(module.provideChoice(noConfigurationFile))
+ .isEqualTo(BlobExportImplChoice.localFile());
+ }
+
+ @Test
+ void provideChoiceShouldThrowWhenConfigurationIsUnknown() throws Exception {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("blob.export.implementation", "unknown");
+
+ FakePropertiesProvider noConfigurationFile = FakePropertiesProvider.builder()
+ .register(NAME, configuration)
+ .build();
+
+ assertThatThrownBy(() -> module.provideChoice(noConfigurationFile))
+ .isInstanceOf(ConfigurationException.class);
+ }
+
+ @Test
+ void provideChoiceShouldThrowWhenConfigurationIsMissing() throws Exception {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ FakePropertiesProvider noConfigurationFile = FakePropertiesProvider.builder()
+ .register(NAME, configuration)
+ .build();
+
+ assertThatThrownBy(() -> module.provideChoice(noConfigurationFile))
+ .isInstanceOf(ConfigurationException.class);
+ }
+
+ @Test
+ void provideMechanismShouldProvideFileExportWhenPassingLocalFileChoice() {
+ assertThat(module.provideMechanism(BlobExportImplChoice.localFile(), LOCAL_FILE_EXPORT_PROVIDER))
+ .isEqualTo(LOCAL_FILE_EXPORT);
+ }
+}
\ No newline at end of file
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index f5f74d5..ee05ad2 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -19,7 +19,7 @@
package org.apache.james;
-import org.apache.james.modules.LocalFileBlobExportMechanismModule;
+import org.apache.james.modules.BlobExportMechanismModule;
import org.apache.james.modules.MailboxModule;
import org.apache.james.modules.activemq.ActiveMQQueueModule;
import org.apache.james.modules.data.CassandraDLPConfigurationStoreModule;
@@ -98,6 +98,10 @@ public class CassandraJamesServerMain {
public static final Module PLUGINS = Modules.combine(
new CassandraQuotaMailingModule());
+ private static final Module BLOB_MODULE = Modules.combine(
+ new BlobStoreAPIModule(),
+ new BlobExportMechanismModule());
+
public static final Module CASSANDRA_SERVER_CORE_MODULE = Modules.combine(
new ActiveMQQueueModule(),
new CassandraDomainListModule(),
@@ -105,12 +109,12 @@ public class CassandraJamesServerMain {
new CassandraEventStoreModule(),
new CassandraMailRepositoryModule(),
new CassandraMetricsModule(),
- new BlobStoreAPIModule(),
new CassandraObjectStoreModule(),
new CassandraRecipientRewriteTableModule(),
new CassandraSessionModule(),
new CassandraSieveRepositoryModule(),
- new CassandraUsersRepositoryModule());
+ new CassandraUsersRepositoryModule(),
+ BLOB_MODULE);
public static final Module CASSANDRA_MAILBOX_MODULE = Modules.combine(
new CassandraMailboxModule(),
@@ -125,8 +129,7 @@ public class CassandraJamesServerMain {
CASSANDRA_SERVER_CORE_MODULE,
CASSANDRA_MAILBOX_MODULE,
PROTOCOLS,
- PLUGINS,
- new LocalFileBlobExportMechanismModule());
+ PLUGINS);
public static void main(String[] args) throws Exception {
Configuration configuration = Configuration.builder()
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
index 7ea6499..1e53751 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -20,8 +20,8 @@
package org.apache.james;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.modules.BlobExportMechanismModule;
import org.apache.james.modules.BlobMemoryModule;
-import org.apache.james.modules.LocalFileBlobExportMechanismModule;
import org.apache.james.modules.MailboxModule;
import org.apache.james.modules.data.MemoryDataJmapModule;
import org.apache.james.modules.data.MemoryDataModule;
@@ -83,7 +83,7 @@ public class MemoryJamesServerMain {
public static final Module IN_MEMORY_SERVER_MODULE = Modules.combine(
new BlobMemoryModule(),
new DeletedMessageVaultModule(),
- new LocalFileBlobExportMechanismModule(),
+ new BlobExportMechanismModule(),
new MailboxModule(),
new MemoryDataModule(),
new MemoryEventStoreModule(),
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org