diff --git a/.travis.yml b/.travis.yml index 699b82a..db722d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ addons: language: java jdk: - openjdk7 -- oraclejdk7 - oraclejdk8 env: global: 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/CheckAccessTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/CheckAccessTest.java index 8137c6d..296c671 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/CheckAccessTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/CheckAccessTest.java @@ -16,6 +16,7 @@ import java.nio.file.*; import java.util.Properties; +import static com.upplication.s3fs.util.S3EndpointConstant.S3_GLOBAL_URI_TEST; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; @@ -25,10 +26,9 @@ public class CheckAccessTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } // check access diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/CopyTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/CopyTest.java index ea50132..17dd234 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/CopyTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/CopyTest.java @@ -23,10 +23,9 @@ public class CopyTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java index 392beb3..f7e13bc 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java @@ -12,22 +12,17 @@ import java.io.IOException; 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.mockito.Mockito.*; +import static org.junit.Assert.*; public class CreateDirectoryTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test @@ -51,6 +46,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,8 +85,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); } - } } \ No newline at end of file diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/DeleteTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/DeleteTest.java index 40e44b0..5d7fd27 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/DeleteTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/DeleteTest.java @@ -26,10 +26,9 @@ public class DeleteTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileAttributeViewTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileAttributeViewTest.java index d5fa5b9..58e00ca 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileAttributeViewTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileAttributeViewTest.java @@ -26,13 +26,11 @@ public class GetFileAttributeViewTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } - @Test public void getBasicFileAttributeView() throws IOException { AmazonS3ClientMock client = AmazonS3MockFactory.getAmazonClientMock(); diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileStoreTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileStoreTest.java index 3c4e7ea..db955b3 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileStoreTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/GetFileStoreTest.java @@ -22,13 +22,11 @@ public class GetFileStoreTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } - @Test(expected = UnsupportedOperationException.class) public void getFileStore() throws IOException { // fixtures diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/GetPathTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/GetPathTest.java index 4f58ad2..0213bc1 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/GetPathTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/GetPathTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3UnitTestBase; +import com.upplication.s3fs.util.S3EndpointConstant; import org.junit.Before; import org.junit.Test; @@ -19,13 +20,11 @@ public class GetPathTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } - @Test public void getPathWithEmtpyEndpoint() throws IOException { FileSystem fs = FileSystems.newFileSystem(URI.create("s3:///"), ImmutableMap.of()); diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/IsHiddenTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/IsHiddenTest.java index 74b4347..b71143d 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/IsHiddenTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/IsHiddenTest.java @@ -22,10 +22,9 @@ public class IsHiddenTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/IsSameFileTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/IsSameFileTest.java index 0ef5eb2..0b45e89 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/IsSameFileTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/IsSameFileTest.java @@ -22,10 +22,9 @@ public class IsSameFileTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/MoveTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/MoveTest.java index 2f3603d..a3c184d 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/MoveTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/MoveTest.java @@ -21,10 +21,9 @@ public class MoveTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewByteChannelTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewByteChannelTest.java index 977843d..2778c53 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewByteChannelTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewByteChannelTest.java @@ -26,13 +26,11 @@ public class NewByteChannelTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } - @Test public void seekable() throws IOException { // fixtures diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewDirectoryStreamTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewDirectoryStreamTest.java index e36f753..3ca2177 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewDirectoryStreamTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewDirectoryStreamTest.java @@ -23,10 +23,9 @@ public class NewDirectoryStreamTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewFileSystemTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewFileSystemTest.java index ffad467..93a01e1 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewFileSystemTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewFileSystemTest.java @@ -23,6 +23,7 @@ import java.nio.file.FileSystemAlreadyExistsException; import java.util.Map; import java.util.Properties; +import java.util.UUID; import org.junit.Before; import org.junit.Test; @@ -41,10 +42,9 @@ public class NewFileSystemTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test(expected = S3FileSystemConfigurationException.class) @@ -81,9 +81,10 @@ public void newS3FileSystemWithCustomHostAndBucket() { @Test public void createsAuthenticatedByEnv() { Map env = buildFakeEnv(); - FileSystem fileSystem = s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, env); + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); + FileSystem fileSystem = s3fsProvider.newFileSystem(uri, env); assertNotNull(fileSystem); - verify(s3fsProvider).createFileSystem(eq(S3EndpointConstant.S3_GLOBAL_URI_TEST), eq(buildFakeProps((String) env.get(ACCESS_KEY), (String) env.get(SECRET_KEY)))); + verify(s3fsProvider).createFileSystem(eq(uri), eq(buildFakeProps((String) env.get(ACCESS_KEY), (String) env.get(SECRET_KEY)))); } @Test @@ -93,7 +94,7 @@ public void setEncodingByProperties() { props.setProperty(ACCESS_KEY, "better_access_key"); props.setProperty(CHARSET_KEY, "UTF-8"); doReturn(props).when(s3fsProvider).loadAmazonProperties(); - URI uri = S3EndpointConstant.S3_GLOBAL_URI_TEST; + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); FileSystem fileSystem = s3fsProvider.newFileSystem(uri, ImmutableMap.of()); assertNotNull(fileSystem); @@ -107,7 +108,7 @@ public void createAuthenticatedByProperties() { props.setProperty(SECRET_KEY, "better_secret_key"); props.setProperty(ACCESS_KEY, "better_access_key"); doReturn(props).when(s3fsProvider).loadAmazonProperties(); - URI uri = S3EndpointConstant.S3_GLOBAL_URI_TEST; + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); FileSystem fileSystem = s3fsProvider.newFileSystem(uri, ImmutableMap.of()); assertNotNull(fileSystem); @@ -120,14 +121,15 @@ public void createAuthenticatedBySystemEnvironment() { final String accessKey = "better-access-key"; final String secretKey = "better-secret-key"; + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); doReturn(accessKey).when(s3fsProvider).systemGetEnv(ACCESS_KEY); doReturn(secretKey).when(s3fsProvider).systemGetEnv(SECRET_KEY); doCallRealMethod().when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + s3fsProvider.newFileSystem(uri, ImmutableMap.of()); - verify(s3fsProvider).createFileSystem(eq(S3EndpointConstant.S3_GLOBAL_URI_TEST), argThat(new ArgumentMatcher() { + verify(s3fsProvider).createFileSystem(eq(uri), argThat(new ArgumentMatcher() { @Override public boolean matches(Object argument) { Properties called = (Properties) argument; @@ -140,7 +142,7 @@ public boolean matches(Object argument) { @Test public void createsAnonymous() { - URI uri = S3EndpointConstant.S3_GLOBAL_URI_TEST; + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); FileSystem fileSystem = s3fsProvider.newFileSystem(uri, ImmutableMap.of()); assertNotNull(fileSystem); verify(s3fsProvider).createFileSystem(eq(uri), eq(buildFakeProps(null, null))); @@ -164,9 +166,12 @@ public void createWithDefaultEndpoint() { @Test(expected = IllegalArgumentException.class) public void createWithOnlyAccessKey() { Properties props = new Properties(); + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); + props.setProperty(ACCESS_KEY, "better_access_key"); doReturn(props).when(s3fsProvider).loadAmazonProperties(); - s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + + s3fsProvider.newFileSystem(uri, ImmutableMap.of()); } @Test(expected = IllegalArgumentException.class) @@ -174,31 +179,42 @@ public void createWithOnlySecretKey() { Properties props = new Properties(); props.setProperty(SECRET_KEY, "better_secret_key"); doReturn(props).when(s3fsProvider).loadAmazonProperties(); - s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); + + s3fsProvider.newFileSystem(uri, ImmutableMap.of()); } @Test(expected = FileSystemAlreadyExistsException.class) public void createFailsIfAlreadyCreated() { FileSystem fileSystem = s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); assertNotNull(fileSystem); - s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); + + s3fsProvider.newFileSystem(uri, ImmutableMap.of()); } @Test(expected = IllegalArgumentException.class) public void createWithWrongEnv() { Map env = ImmutableMap.builder().put(ACCESS_KEY, 1234).put(SECRET_KEY, "secret key").build(); - FileSystem fileSystem = s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, env); + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); + + FileSystem fileSystem = s3fsProvider.newFileSystem(uri, env); assertNotNull(fileSystem); - s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + + s3fsProvider.newFileSystem(uri, ImmutableMap.of()); } @Test public void getFileSystem() { - FileSystem fileSystem = s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + URI uri = URI.create("s3://" + UUID.randomUUID().toString()); + + FileSystem fileSystem = s3fsProvider.newFileSystem(uri, ImmutableMap.of()); assertNotNull(fileSystem); - fileSystem = s3fsProvider.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, ImmutableMap.of()); + + fileSystem = s3fsProvider.getFileSystem(uri, ImmutableMap.of()); assertNotNull(fileSystem); - FileSystem other = s3fsProvider.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST); + + FileSystem other = s3fsProvider.getFileSystem(uri); assertSame(fileSystem, other); } diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewInputStreamTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewInputStreamTest.java index 3dd71fa..3e14e79 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewInputStreamTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewInputStreamTest.java @@ -30,10 +30,9 @@ public class NewInputStreamTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewOutputStreamTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewOutputStreamTest.java index 41df1e5..de5bf6f 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/NewOutputStreamTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/NewOutputStreamTest.java @@ -27,10 +27,9 @@ public class NewOutputStreamTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/ReadAttributesTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/ReadAttributesTest.java index b5cb86d..8dfdb04 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/ReadAttributesTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/ReadAttributesTest.java @@ -21,10 +21,9 @@ public class ReadAttributesTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } diff --git a/src/test/java/com/upplication/s3fs/FileSystemProvider/SetAttributeTest.java b/src/test/java/com/upplication/s3fs/FileSystemProvider/SetAttributeTest.java index 2c67b7c..6eda210 100644 --- a/src/test/java/com/upplication/s3fs/FileSystemProvider/SetAttributeTest.java +++ b/src/test/java/com/upplication/s3fs/FileSystemProvider/SetAttributeTest.java @@ -22,10 +22,9 @@ public class SetAttributeTest extends S3UnitTestBase { private S3FileSystemProvider s3fsProvider; @Before - public void setup() { - s3fsProvider = spy(new S3FileSystemProvider()); - doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); - doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } diff --git a/src/test/java/com/upplication/s3fs/Path/EndsWithTest.java b/src/test/java/com/upplication/s3fs/Path/EndsWithTest.java index bd38ee6..dd93f23 100644 --- a/src/test/java/com/upplication/s3fs/Path/EndsWithTest.java +++ b/src/test/java/com/upplication/s3fs/Path/EndsWithTest.java @@ -1,6 +1,7 @@ package com.upplication.s3fs.Path; import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -19,14 +20,16 @@ public class EndsWithTest extends S3UnitTestBase { - @Before - public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + @Before + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/EqualsTest.java b/src/test/java/com/upplication/s3fs/Path/EqualsTest.java index 5ca0cbf..aeb1150 100644 --- a/src/test/java/com/upplication/s3fs/Path/EqualsTest.java +++ b/src/test/java/com/upplication/s3fs/Path/EqualsTest.java @@ -1,6 +1,7 @@ package com.upplication.s3fs.Path; import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -18,14 +19,16 @@ public class EqualsTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/GetFilenameTest.java b/src/test/java/com/upplication/s3fs/Path/GetFileNameTest.java similarity index 78% rename from src/test/java/com/upplication/s3fs/Path/GetFilenameTest.java rename to src/test/java/com/upplication/s3fs/Path/GetFileNameTest.java index 44a4e70..98e7249 100644 --- a/src/test/java/com/upplication/s3fs/Path/GetFilenameTest.java +++ b/src/test/java/com/upplication/s3fs/Path/GetFileNameTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -16,14 +17,16 @@ public class GetFileNameTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/GetKeyTest.java b/src/test/java/com/upplication/s3fs/Path/GetKeyTest.java index 86f07fb..76377c1 100644 --- a/src/test/java/com/upplication/s3fs/Path/GetKeyTest.java +++ b/src/test/java/com/upplication/s3fs/Path/GetKeyTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -14,14 +15,16 @@ public class GetKeyTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/GetNameTest.java b/src/test/java/com/upplication/s3fs/Path/GetNameTest.java index 8da4353..30ad5ee 100644 --- a/src/test/java/com/upplication/s3fs/Path/GetNameTest.java +++ b/src/test/java/com/upplication/s3fs/Path/GetNameTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -14,14 +15,16 @@ public class GetNameTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test(expected = IllegalArgumentException.class) diff --git a/src/test/java/com/upplication/s3fs/Path/GetRootTest.java b/src/test/java/com/upplication/s3fs/Path/GetRootTest.java index b221e66..12b5d00 100644 --- a/src/test/java/com/upplication/s3fs/Path/GetRootTest.java +++ b/src/test/java/com/upplication/s3fs/Path/GetRootTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -15,13 +16,16 @@ public class GetRootTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/ItearatorTest.java b/src/test/java/com/upplication/s3fs/Path/ItearatorTest.java index 4243691..6394fb7 100644 --- a/src/test/java/com/upplication/s3fs/Path/ItearatorTest.java +++ b/src/test/java/com/upplication/s3fs/Path/ItearatorTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -16,14 +17,16 @@ public class ItearatorTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/ResolveSiblingTest.java b/src/test/java/com/upplication/s3fs/Path/ResolveSiblingTest.java index 75af3dc..9fabdc5 100644 --- a/src/test/java/com/upplication/s3fs/Path/ResolveSiblingTest.java +++ b/src/test/java/com/upplication/s3fs/Path/ResolveSiblingTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -14,14 +15,16 @@ public class ResolveSiblingTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } diff --git a/src/test/java/com/upplication/s3fs/Path/ResolveTest.java b/src/test/java/com/upplication/s3fs/Path/ResolveTest.java index 2a560f9..5873e48 100644 --- a/src/test/java/com/upplication/s3fs/Path/ResolveTest.java +++ b/src/test/java/com/upplication/s3fs/Path/ResolveTest.java @@ -1,6 +1,6 @@ package com.upplication.s3fs.Path; -import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -8,21 +8,22 @@ import org.junit.Test; import java.io.IOException; -import java.nio.file.FileSystems; import static com.upplication.s3fs.util.S3EndpointConstant.S3_GLOBAL_URI_TEST; import static org.junit.Assert.assertEquals; public class ResolveTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/S3PathTest.java b/src/test/java/com/upplication/s3fs/Path/S3PathTest.java index fcf38b4..5ea0e6c 100644 --- a/src/test/java/com/upplication/s3fs/Path/S3PathTest.java +++ b/src/test/java/com/upplication/s3fs/Path/S3PathTest.java @@ -14,14 +14,21 @@ import java.nio.file.WatchEvent; import java.util.HashMap; +import static com.upplication.s3fs.util.S3EndpointConstant.S3_GLOBAL_URI_TEST; import static org.junit.Assert.*; public class S3PathTest extends S3UnitTestBase { + private S3FileSystemProvider s3fsProvider; + + private S3Path forPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + } + @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test @@ -179,13 +186,13 @@ public void hashCodeHashMap() { @Test(expected = IllegalArgumentException.class) public void preconditions() { - S3FileSystem fileSystem = new S3FileSystemProvider().getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST); + S3FileSystem fileSystem = s3fsProvider.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST); new S3Path(fileSystem, "/"); } @Test public void constructors() { - S3FileSystem fileSystem = new S3FileSystemProvider().getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST); + S3FileSystem fileSystem = s3fsProvider.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST); S3Path path = new S3Path(fileSystem, "/buckname"); assertEquals("buckname", path.getFileStore().name()); assertEquals("", path.getKey()); @@ -225,8 +232,4 @@ public void registerWatchService() throws IOException { S3Path path = forPath("/buck/file"); path.register(null, new WatchEvent.Kind[0], new WatchEvent.Modifier[0]); } - - private static S3Path forPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST).getPath(path); - } } \ No newline at end of file diff --git a/src/test/java/com/upplication/s3fs/Path/StartsWithTest.java b/src/test/java/com/upplication/s3fs/Path/StartsWithTest.java index 7ffc02f..0dcd165 100644 --- a/src/test/java/com/upplication/s3fs/Path/StartsWithTest.java +++ b/src/test/java/com/upplication/s3fs/Path/StartsWithTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -16,14 +17,16 @@ public class StartsWithTest extends S3UnitTestBase { - @Before - public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + @Before + public void setup() throws IOException { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test diff --git a/src/test/java/com/upplication/s3fs/Path/SubpathTest.java b/src/test/java/com/upplication/s3fs/Path/SubpathTest.java index 934d055..6518b6a 100644 --- a/src/test/java/com/upplication/s3fs/Path/SubpathTest.java +++ b/src/test/java/com/upplication/s3fs/Path/SubpathTest.java @@ -1,5 +1,6 @@ package com.upplication.s3fs.Path; +import com.upplication.s3fs.S3FileSystemProvider; import com.upplication.s3fs.S3Path; import com.upplication.s3fs.S3UnitTestBase; import com.upplication.s3fs.util.S3EndpointConstant; @@ -14,19 +15,20 @@ public class SubpathTest extends S3UnitTestBase { - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3FileSystemProvider s3fsProvider; + + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } @Before public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test public void subPath0() { - // TODO: this is ok? assertEquals(getPath("/bucket/path/"), getPath("/bucket/path/to/file").subpath(0, 1)); } diff --git a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java index 209a795..1bd1193 100644 --- a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java +++ b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java @@ -12,9 +12,12 @@ import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; +import java.nio.file.FileSystemNotFoundException; import java.nio.file.FileSystems; import java.nio.file.Path; +import java.util.HashMap; import java.util.Map; +import java.util.Properties; import static com.upplication.s3fs.AmazonS3Factory.ACCESS_KEY; import static com.upplication.s3fs.AmazonS3Factory.SECRET_KEY; @@ -22,13 +25,21 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyMap; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; public class ToUriTest extends S3UnitTestBase { + private S3FileSystemProvider s3fsProvider; + @Before - public void setup() throws IOException { - FileSystems - .newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); + public void setup() { + s3fsProvider = getS3fsProvider(); + s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null); } @Test @@ -40,10 +51,9 @@ public void toUri() { assertEquals("s3", uri.getScheme()); // could get the correct fileSystem - FileSystem fs = FileSystems.getFileSystem(uri); - assertTrue(fs instanceof S3FileSystem); + S3FileSystem fs = s3fsProvider.getFileSystem(uri); // the host is the endpoint specified in fileSystem - assertEquals(((S3FileSystem) fs).getEndpoint(), uri.getHost()); + assertEquals(fs.getEndpoint(), uri.getHost()); // bucket name as first path Path pathActual = fs.provider().getPath(uri); @@ -67,8 +77,7 @@ public void toUriWithNotEndSlash() { @Test public void toUriRelative() { - S3FileSystem fileSystem = new S3FileSystemProvider() - .getFileSystem(S3_GLOBAL_URI_TEST); + S3FileSystem fileSystem = s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST); S3Path path = new S3Path(fileSystem, "bla"); assertEquals(URI.create("bla"), path.toUri()); @@ -84,17 +93,32 @@ public void toUriBucketWithoutEndSlash() { @Test public void toUriWithCredentials() { Map envs = ImmutableMap.builder().put(ACCESS_KEY, "access").put(SECRET_KEY, "secret").build(); - FileSystem fileSystem = new S3FileSystemProvider() - .newFileSystem(S3_GLOBAL_URI_TEST, envs); + FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI_TEST, envs); Path path = fileSystem.getPath("/bla/file"); assertEquals(URI.create("s3://access@s3.test.amazonaws.com/bla/file"), path.toUri()); } + @Test + public void toUriWithCredentialBySystemProperty() { + + System.setProperty(ACCESS_KEY, "accessKeywii"); + System.setProperty(SECRET_KEY, "secretKey"); + + FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI_TEST, null); + + 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)) { + try (FileSystem fs = s3fsProvider.newFileSystem(URI.create("s3://endpoint/"), null)) { Path path = fs.getPath("/bucket/path/to/file"); URI uri = path.toUri(); // the scheme is s3 @@ -104,7 +128,7 @@ public void toUriWithEndpoint() throws IOException { } } - private static S3Path getPath(String path) { - return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); + private S3Path getPath(String path) { + return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path); } } diff --git a/src/test/java/com/upplication/s3fs/S3UnitTestBase.java b/src/test/java/com/upplication/s3fs/S3UnitTestBase.java index b9ade2e..ff9f559 100644 --- a/src/test/java/com/upplication/s3fs/S3UnitTestBase.java +++ b/src/test/java/com/upplication/s3fs/S3UnitTestBase.java @@ -1,24 +1,49 @@ 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 static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; import org.junit.After; +import org.junit.Before; import org.junit.BeforeClass; import com.upplication.s3fs.util.AmazonS3ClientMock; import com.upplication.s3fs.util.AmazonS3MockFactory; +import java.util.Properties; + public class S3UnitTestBase { + private S3FileSystemProvider s3fsProvider; + @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"); } + @Before + public void setupS3fsProvider() { + s3fsProvider = spy(new S3FileSystemProvider()); + // stub the possibility to add system envs var + doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString()); + doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties(); + } + @After public void closeMemory() { AmazonS3ClientMock client = AmazonS3MockFactory.getAmazonClientMock(); client.clear(); + for (S3FileSystem s3FileSystem : S3FileSystemProvider.getFilesystems().values()) { try { s3FileSystem.close(); @@ -27,4 +52,8 @@ public void closeMemory() { } } } + + public S3FileSystemProvider getS3fsProvider() { + return this.s3fsProvider; + } } \ No newline at end of file diff --git a/src/test/java/com/upplication/s3fs/util/S3EndpointConstant.java b/src/test/java/com/upplication/s3fs/util/S3EndpointConstant.java index 6c49639..5e434fb 100644 --- a/src/test/java/com/upplication/s3fs/util/S3EndpointConstant.java +++ b/src/test/java/com/upplication/s3fs/util/S3EndpointConstant.java @@ -4,7 +4,6 @@ public class S3EndpointConstant { - public static final URI S3_GLOBAL_URI_TEST = URI.create("s3://s3.test.amazonaws.com/"); public static final URI S3_GLOBAL_URI_IT = URI.create("s3://s3.amazonaws.com/"); }