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

Commit 68a5473

Browse files
author
Tim Wolters
committed
Added mandatory unittest for resolve
1 parent e2a7675 commit 68a5473

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

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

3+
import com.upplication.s3fs.AmazonS3Factory;
34
import com.upplication.s3fs.S3FileSystem;
45
import com.upplication.s3fs.S3FileSystemProvider;
56
import com.upplication.s3fs.S3Path;
@@ -9,8 +10,10 @@
910
import org.junit.Test;
1011

1112
import java.io.IOException;
13+
import java.net.URI;
1214
import java.nio.file.FileSystems;
1315
import java.nio.file.Path;
16+
import java.nio.file.Paths;
1417
import java.nio.file.WatchEvent;
1518
import java.util.HashMap;
1619

@@ -232,4 +235,55 @@ public void registerWatchService() throws IOException {
232235
S3Path path = forPath("/buck/file");
233236
path.register(null, new WatchEvent.Kind<?>[0], new WatchEvent.Modifier[0]);
234237
}
238+
@Test
239+
public void testResolve() throws IOException {
240+
S3FileSystem fileSystem2 = null;
241+
try {
242+
HashMap<String, String> environments = new HashMap<>();
243+
environments.put(AmazonS3Factory.ACCESS_KEY, "accesskey");
244+
environments.put(AmazonS3Factory.SECRET_KEY, "secretaccesskey");
245+
246+
fileSystem2 = (S3FileSystem) FileSystems.newFileSystem(URI.create("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket"), environments);
247+
248+
//good
249+
S3Path parent = (S3Path) fileSystem2.provider().getPath(URI.create("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket"));
250+
S3Path child = (S3Path) fileSystem2.provider().getPath(URI.create("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit"));
251+
S3Path resolved = (S3Path) parent.resolve(child);
252+
253+
assertEquals(child, resolved);
254+
255+
resolved = (S3Path) parent.resolve("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit");
256+
assertEquals(child, resolved);
257+
258+
resolved = (S3Path) parent.resolve("rabbit");
259+
assertEquals(child, resolved);
260+
261+
resolved = (S3Path) parent.resolve(Paths.get("rabbit")); //unixPath
262+
assertEquals(child, resolved);
263+
264+
resolved = (S3Path) parent.resolve(Paths.get("./rabbit")); //unixPath
265+
assertEquals("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/./rabbit", resolved.toString());
266+
267+
resolved = (S3Path) parent.resolve(Paths.get("./rabbit in space")); //unixPath
268+
assertEquals("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/./rabbit%20in%20space", resolved.toString());
269+
270+
try {
271+
parent.resolve(Paths.get("/tmp"));
272+
fail("expect IllegalArgumentException");
273+
} catch (IllegalArgumentException e) {
274+
//ignore
275+
assertEquals("other must be an instance of com.upplication.s3fs.S3Path or be relative", e.getMessage());
276+
}
277+
278+
//bad
279+
S3Path parent2 = fileSystem2.getPath("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket");
280+
S3Path child2 = fileSystem2.getPath("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit");
281+
S3Path resolved2 = (S3Path) parent2.resolve(child2);
282+
assertEquals("s3:/accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/s3:/accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit", resolved2.toString());
283+
284+
} finally {
285+
if (fileSystem2 != null)
286+
fileSystem2.close();
287+
}
288+
}
235289
}

0 commit comments

Comments
 (0)