From 519195efdcac7a766ab6842882873325cecf22d6 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 28 Nov 2017 17:34:58 +0100 Subject: [PATCH] :bug: Fix case sensitive test name --- .../upplication/s3fs/S3FileSystemProvider.java | 9 +++++++++ src/main/java/com/upplication/s3fs/S3Path.java | 8 ++------ .../CreateDirectoryTest.java | 7 +++---- ...tFilenameTest.java => GetFileNameTest.java} | 0 .../com/upplication/s3fs/Path/ToUriTest.java | 18 ++++++++++++++++++ .../com/upplication/s3fs/S3UnitTestBase.java | 8 ++++++++ 6 files changed, 40 insertions(+), 10 deletions(-) rename src/test/java/com/upplication/s3fs/Path/{GetFilenameTest.java => GetFileNameTest.java} (100%) diff --git a/src/main/java/com/upplication/s3fs/S3FileSystemProvider.java b/src/main/java/com/upplication/s3fs/S3FileSystemProvider.java index e136cd3..757dab3 100644 --- a/src/main/java/com/upplication/s3fs/S3FileSystemProvider.java +++ b/src/main/java/com/upplication/s3fs/S3FileSystemProvider.java @@ -229,6 +229,10 @@ public boolean overloadPropertiesWithSystemProps(Properties props, String key) { } /** + * The system envs have preference over the properties files. + * So we overload it + * @param props Properties + * @param key String * @return true if the key are overloaded by a system property */ public boolean overloadPropertiesWithSystemEnv(Properties props, String key) { @@ -239,6 +243,11 @@ public boolean overloadPropertiesWithSystemEnv(Properties props, String key) { return false; } + /** + * Get the system env with the key param + * @param key String + * @return String or null + */ public String systemGetEnv(String key) { return System.getenv(key); } diff --git a/src/main/java/com/upplication/s3fs/S3Path.java b/src/main/java/com/upplication/s3fs/S3Path.java index 5dadc9a..4ca813f 100644 --- a/src/main/java/com/upplication/s3fs/S3Path.java +++ b/src/main/java/com/upplication/s3fs/S3Path.java @@ -116,6 +116,8 @@ public S3FileStore getFileStore() { /** * key for amazon without final slash. * note: the final slash need to be added to save a directory (Amazon s3 spec) + * + * @return the key for AmazonS3Client */ public String getKey() { @@ -125,12 +127,6 @@ public String getKey() { key = key.substring(1, key.length()); } - // TODO: review this... :S - /* - if (key.endsWith("/")) { - key = key.substring(0, key.length()-1); - } - */ return key; } diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java index 392beb3..ae93ece 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java @@ -14,9 +14,7 @@ import java.nio.file.*; import java.util.Properties; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.*; public class CreateDirectoryTest extends S3UnitTestBase { @@ -51,6 +49,7 @@ public void createDirectoryInNewBucket() throws IOException { S3Path root = createNewS3FileSystem().getPath("/newer-bucket"); Path resolve = root.resolve("folder"); Path path = Files.createDirectories(resolve); + assertEquals("s3://s3.test.amazonaws.com/newer-bucket/folder", path.toAbsolutePath().toString()); // assert assertTrue(Files.exists(root)); @@ -89,7 +88,7 @@ private S3FileSystem createNewS3FileSystem() throws IOException { try { return s3fsProvider.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST); } catch (FileSystemNotFoundException e) { - return (S3FileSystem) FileSystems.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + return (S3FileSystem) s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } } diff --git a/src/test/java/com/upplication/s3fs/Path/GetFilenameTest.java b/src/test/java/com/upplication/s3fs/Path/GetFileNameTest.java similarity index 100% rename from src/test/java/com/upplication/s3fs/Path/GetFilenameTest.java rename to src/test/java/com/upplication/s3fs/Path/GetFileNameTest.java diff --git a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java index 209a795..6e24fa6 100644 --- a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java +++ b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java @@ -14,6 +14,7 @@ import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; +import java.util.HashMap; import java.util.Map; import static com.upplication.s3fs.AmazonS3Factory.ACCESS_KEY; @@ -92,6 +93,23 @@ public void toUriWithCredentials() { assertEquals(URI.create("s3://access@s3.test.amazonaws.com/bla/file"), path.toUri()); } + @Test + public void toUriWithCredentialBySystemenv() { + + System.setProperty(ACCESS_KEY, "accessKeywii"); + System.setProperty(SECRET_KEY, "secretKey"); + + FileSystem fileSystem = new S3FileSystemProvider() + .newFileSystem(S3_GLOBAL_URI_TEST, new HashMap()); + + Path path = fileSystem.getPath("/bla/file"); + + assertEquals(URI.create("s3://accessKeywii@s3.test.amazonaws.com/bla/file"), path.toUri()); + + System.clearProperty(ACCESS_KEY); + System.clearProperty(SECRET_KEY); + } + @Test public void toUriWithEndpoint() throws IOException { try (FileSystem fs = FileSystems.newFileSystem(URI.create("s3://endpoint/"), null)) { diff --git a/src/test/java/com/upplication/s3fs/S3UnitTestBase.java b/src/test/java/com/upplication/s3fs/S3UnitTestBase.java index b9ade2e..e227a9e 100644 --- a/src/test/java/com/upplication/s3fs/S3UnitTestBase.java +++ b/src/test/java/com/upplication/s3fs/S3UnitTestBase.java @@ -1,5 +1,7 @@ package com.upplication.s3fs; +import static com.upplication.s3fs.AmazonS3Factory.ACCESS_KEY; +import static com.upplication.s3fs.AmazonS3Factory.SECRET_KEY; import static com.upplication.s3fs.S3FileSystemProvider.AMAZON_S3_FACTORY_CLASS; import org.junit.After; @@ -12,7 +14,13 @@ public class S3UnitTestBase { @BeforeClass public static void setProperties() { + + System.clearProperty(S3FileSystemProvider.AMAZON_S3_FACTORY_CLASS); + System.clearProperty(ACCESS_KEY); + System.clearProperty(SECRET_KEY); + System.setProperty(AMAZON_S3_FACTORY_CLASS, "com.upplication.s3fs.util.AmazonS3MockFactory"); + } @After