Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 9216d8b

Browse files
committed
🐛 Fix case sensitive test name
1 parent 83890c0 commit 9216d8b

File tree

6 files changed

+59
-21
lines changed

6 files changed

+59
-21
lines changed

src/main/java/com/upplication/s3fs/S3FileSystemProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ public boolean overloadPropertiesWithSystemProps(Properties props, String key) {
229229
}
230230

231231
/**
232+
* The system envs have preference over the properties files.
233+
* So we overload it
234+
* @param props Properties
235+
* @param key String
232236
* @return true if the key are overloaded by a system property
233237
*/
234238
public boolean overloadPropertiesWithSystemEnv(Properties props, String key) {
@@ -239,6 +243,11 @@ public boolean overloadPropertiesWithSystemEnv(Properties props, String key) {
239243
return false;
240244
}
241245

246+
/**
247+
* Get the system env with the key param
248+
* @param key String
249+
* @return String or null
250+
*/
242251
public String systemGetEnv(String key) {
243252
return System.getenv(key);
244253
}

src/main/java/com/upplication/s3fs/S3Path.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public S3FileStore getFileStore() {
116116
/**
117117
* key for amazon without final slash.
118118
* <b>note:</b> the final slash need to be added to save a directory (Amazon s3 spec)
119+
*
120+
* @return the key for AmazonS3Client
119121
*/
120122
public String getKey() {
121123

@@ -125,12 +127,6 @@ public String getKey() {
125127
key = key.substring(1, key.length());
126128
}
127129

128-
// TODO: review this... :S
129-
/*
130-
if (key.endsWith("/")) {
131-
key = key.substring(0, key.length()-1);
132-
}
133-
*/
134130
return key;
135131
}
136132

src/test/java/com/upplication/s3fs/FileSystemProvider/CreateDirectoryTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import java.nio.file.*;
1515
import java.util.Properties;
1616

17-
import static org.junit.Assert.assertArrayEquals;
18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.Assert.*;
2018
import static org.mockito.Mockito.*;
2119

2220
public class CreateDirectoryTest extends S3UnitTestBase {
@@ -51,6 +49,7 @@ public void createDirectoryInNewBucket() throws IOException {
5149
S3Path root = createNewS3FileSystem().getPath("/newer-bucket");
5250
Path resolve = root.resolve("folder");
5351
Path path = Files.createDirectories(resolve);
52+
5453
assertEquals("s3://s3.test.amazonaws.com/newer-bucket/folder", path.toAbsolutePath().toString());
5554
// assert
5655
assertTrue(Files.exists(root));
@@ -89,8 +88,7 @@ private S3FileSystem createNewS3FileSystem() throws IOException {
8988
try {
9089
return s3fsProvider.getFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST);
9190
} catch (FileSystemNotFoundException e) {
92-
return (S3FileSystem) FileSystems.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null);
91+
return (S3FileSystem) s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null);
9392
}
94-
9593
}
9694
}

src/test/java/com/upplication/s3fs/Path/ToUriTest.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,36 @@
1212
import java.io.IOException;
1313
import java.net.URI;
1414
import java.nio.file.FileSystem;
15+
import java.nio.file.FileSystemNotFoundException;
1516
import java.nio.file.FileSystems;
1617
import java.nio.file.Path;
18+
import java.util.HashMap;
1719
import java.util.Map;
20+
import java.util.Properties;
1821

1922
import static com.upplication.s3fs.AmazonS3Factory.ACCESS_KEY;
2023
import static com.upplication.s3fs.AmazonS3Factory.SECRET_KEY;
2124
import static com.upplication.s3fs.util.S3EndpointConstant.*;
2225

2326
import static org.junit.Assert.assertEquals;
2427
import static org.junit.Assert.assertTrue;
28+
import static org.mockito.Matchers.any;
29+
import static org.mockito.Matchers.anyString;
30+
import static org.mockito.Mockito.doReturn;
31+
import static org.mockito.Mockito.spy;
2532

2633
public class ToUriTest extends S3UnitTestBase {
2734

35+
private S3FileSystemProvider s3fsProvider;
36+
2837
@Before
29-
public void setup() throws IOException {
30-
FileSystems
31-
.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null);
38+
public void setup() {
39+
s3fsProvider = spy(new S3FileSystemProvider());
40+
// stub the possibility to add system envs var
41+
doReturn(false).when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString());
42+
doReturn(new Properties()).when(s3fsProvider).loadAmazonProperties();
43+
44+
s3fsProvider.newFileSystem(S3EndpointConstant.S3_GLOBAL_URI_TEST, null);
3245
}
3346

3447
@Test
@@ -67,8 +80,7 @@ public void toUriWithNotEndSlash() {
6780

6881
@Test
6982
public void toUriRelative() {
70-
S3FileSystem fileSystem = new S3FileSystemProvider()
71-
.getFileSystem(S3_GLOBAL_URI_TEST);
83+
S3FileSystem fileSystem = s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST);
7284

7385
S3Path path = new S3Path(fileSystem, "bla");
7486
assertEquals(URI.create("bla"), path.toUri());
@@ -84,17 +96,32 @@ public void toUriBucketWithoutEndSlash() {
8496
@Test
8597
public void toUriWithCredentials() {
8698
Map<String, String> envs = ImmutableMap.<String, String>builder().put(ACCESS_KEY, "access").put(SECRET_KEY, "secret").build();
87-
FileSystem fileSystem = new S3FileSystemProvider()
88-
.newFileSystem(S3_GLOBAL_URI_TEST, envs);
99+
FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI_TEST, envs);
89100

90101
Path path = fileSystem.getPath("/bla/file");
91102

92103
assertEquals(URI.create("s3://[email protected]/bla/file"), path.toUri());
93104
}
94105

106+
@Test
107+
public void toUriWithCredentialBySystemProperty() {
108+
109+
System.setProperty(ACCESS_KEY, "accessKeywii");
110+
System.setProperty(SECRET_KEY, "secretKey");
111+
112+
FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI_TEST, null);
113+
114+
Path path = fileSystem.getPath("/bla/file");
115+
116+
assertEquals(URI.create("s3://[email protected]/bla/file"), path.toUri());
117+
118+
System.clearProperty(ACCESS_KEY);
119+
System.clearProperty(SECRET_KEY);
120+
}
121+
95122
@Test
96123
public void toUriWithEndpoint() throws IOException {
97-
try (FileSystem fs = FileSystems.newFileSystem(URI.create("s3://endpoint/"), null)) {
124+
try (FileSystem fs = s3fsProvider.newFileSystem(URI.create("s3://endpoint/"), null)) {
98125
Path path = fs.getPath("/bucket/path/to/file");
99126
URI uri = path.toUri();
100127
// the scheme is s3
@@ -104,7 +131,7 @@ public void toUriWithEndpoint() throws IOException {
104131
}
105132
}
106133

107-
private static S3Path getPath(String path) {
108-
return (S3Path) FileSystems.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path);
134+
private S3Path getPath(String path) {
135+
return s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST).getPath(path);
109136
}
110137
}

src/test/java/com/upplication/s3fs/S3UnitTestBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.upplication.s3fs;
22

3+
import static com.upplication.s3fs.AmazonS3Factory.ACCESS_KEY;
4+
import static com.upplication.s3fs.AmazonS3Factory.SECRET_KEY;
35
import static com.upplication.s3fs.S3FileSystemProvider.AMAZON_S3_FACTORY_CLASS;
46

57
import org.junit.After;
@@ -12,7 +14,13 @@ public class S3UnitTestBase {
1214

1315
@BeforeClass
1416
public static void setProperties() {
17+
18+
System.clearProperty(S3FileSystemProvider.AMAZON_S3_FACTORY_CLASS);
19+
System.clearProperty(ACCESS_KEY);
20+
System.clearProperty(SECRET_KEY);
21+
1522
System.setProperty(AMAZON_S3_FACTORY_CLASS, "com.upplication.s3fs.util.AmazonS3MockFactory");
23+
1624
}
1725

1826
@After

0 commit comments

Comments
 (0)