mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #9266 from 4Science/DURACOM-211-S3store-is-always-enabled
S3store is always enabled
This commit is contained in:
@@ -169,7 +169,7 @@ public class S3BitStoreService extends BaseBitStoreService {
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
|
||||
if (this.isInitialized()) {
|
||||
if (this.isInitialized() || !this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -42,6 +43,7 @@ import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import io.findify.s3mock.S3Mock;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.dspace.AbstractIntegrationTestWithDatabase;
|
||||
import org.dspace.app.matcher.LambdaMatcher;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -53,6 +55,8 @@ import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Utils;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
@@ -60,6 +64,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Luca Giamminonni (luca.giamminonni at 4science.com)
|
||||
*/
|
||||
@@ -77,9 +82,13 @@ public class S3BitStoreServiceIT extends AbstractIntegrationTestWithDatabase {
|
||||
|
||||
private File s3Directory;
|
||||
|
||||
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
|
||||
configurationService.setProperty("assetstore.s3.enabled", "true");
|
||||
s3Directory = new File(System.getProperty("java.io.tmpdir"), "s3");
|
||||
|
||||
s3Mock = S3Mock.create(8001, s3Directory.getAbsolutePath());
|
||||
@@ -88,7 +97,8 @@ public class S3BitStoreServiceIT extends AbstractIntegrationTestWithDatabase {
|
||||
amazonS3Client = createAmazonS3Client();
|
||||
|
||||
s3BitStoreService = new S3BitStoreService(amazonS3Client);
|
||||
|
||||
s3BitStoreService.setEnabled(BooleanUtils.toBoolean(
|
||||
configurationService.getProperty("assetstore.s3.enabled")));
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
@@ -382,6 +392,17 @@ public class S3BitStoreServiceIT extends AbstractIntegrationTestWithDatabase {
|
||||
assertThat(computedPath, Matchers.not(Matchers.containsString(File.separator)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoNotInitializeConfigured() throws Exception {
|
||||
String assetstores3enabledOldValue = configurationService.getProperty("assetstore.s3.enabled");
|
||||
configurationService.setProperty("assetstore.s3.enabled", "false");
|
||||
s3BitStoreService = new S3BitStoreService(amazonS3Client);
|
||||
s3BitStoreService.init();
|
||||
assertFalse(s3BitStoreService.isInitialized());
|
||||
assertFalse(s3BitStoreService.isEnabled());
|
||||
configurationService.setProperty("assetstore.s3.enabled", assetstores3enabledOldValue);
|
||||
}
|
||||
|
||||
private byte[] generateChecksum(String content) {
|
||||
try {
|
||||
MessageDigest m = MessageDigest.getInstance("MD5");
|
||||
|
Reference in New Issue
Block a user