Skip to content

Commit

Permalink
🐛 Fix case sensitive test name
Browse files Browse the repository at this point in the history
  • Loading branch information
jarnaiz committed Nov 28, 2017
1 parent 83890c0 commit 9216d8b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/upplication/s3fs/S3FileSystemProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/upplication/s3fs/S3Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public S3FileStore getFileStore() {
/**
* key for amazon without final slash.
* <b>note:</b> the final slash need to be added to save a directory (Amazon s3 spec)
*
* @return the key for AmazonS3Client
*/
public String getKey() {

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -89,8 +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);
}

}
}
47 changes: 37 additions & 10 deletions src/test/java/com/upplication/s3fs/Path/ToUriTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,36 @@
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;
import static com.upplication.s3fs.util.S3EndpointConstant.*;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
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 = 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();

s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null);
}

@Test
Expand Down Expand Up @@ -67,8 +80,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());
Expand All @@ -84,17 +96,32 @@ public void toUriBucketWithoutEndSlash() {
@Test
public void toUriWithCredentials() {
Map<String, String> envs = ImmutableMap.<String, String>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
Expand All @@ -104,7 +131,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);
}
}
8 changes: 8 additions & 0 deletions src/test/java/com/upplication/s3fs/S3UnitTestBase.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 9216d8b

Please sign in to comment.