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 519195e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 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,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);
}

}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/upplication/s3fs/Path/ToUriTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object>());

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)) {
Expand Down
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 519195e

Please sign in to comment.