|
6 | 6 | import org.carlspring.cloud.storage.s3fs.util.S3EndpointConstant;
|
7 | 7 |
|
8 | 8 | import java.io.IOException;
|
| 9 | +import java.nio.file.Paths; |
9 | 10 |
|
10 | 11 | import org.junit.jupiter.api.AfterEach;
|
11 | 12 | import org.junit.jupiter.api.BeforeEach;
|
12 | 13 | import org.junit.jupiter.api.Test;
|
13 | 14 | import static org.carlspring.cloud.storage.s3fs.util.S3EndpointConstant.S3_GLOBAL_URI_TEST;
|
14 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 16 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
15 | 17 |
|
16 | 18 | class ResolveTest
|
17 | 19 | extends S3UnitTestBase
|
@@ -64,4 +66,30 @@ void resolve()
|
64 | 66 | assertEquals(getPath("/bucket2/other/child"), getPath("/bucket/path/to/file").resolve("/bucket2/other/child"));
|
65 | 67 | }
|
66 | 68 |
|
| 69 | + |
| 70 | + @Test |
| 71 | + void nonS3Paths() |
| 72 | + { |
| 73 | + S3Path parent = getPath("/bucket"); |
| 74 | + S3Path child = getPath("/bucket/rabbit"); |
| 75 | + S3Path resolved = (S3Path) parent.resolve(child); |
| 76 | + |
| 77 | + assertEquals(child, resolved); |
| 78 | + |
| 79 | + resolved = (S3Path) parent.resolve("rabbit"); |
| 80 | + assertEquals(child, resolved); |
| 81 | + |
| 82 | + resolved = (S3Path) parent.resolve(Paths.get("rabbit")); //unixPath |
| 83 | + assertEquals(child, resolved); |
| 84 | + |
| 85 | + resolved = (S3Path) parent.resolve(Paths.get("./rabbit")); //unixPath |
| 86 | + assertEquals("s3://s3.test.amazonaws.com/bucket/./rabbit", resolved.toString()); |
| 87 | + |
| 88 | + resolved = (S3Path) parent.resolve(Paths.get("./rabbit in space")); //unixPath |
| 89 | + assertEquals("s3://s3.test.amazonaws.com/bucket/./rabbit%20in%20space", resolved.toString()); |
| 90 | + |
| 91 | + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> |
| 92 | + parent.resolve(Paths.get("/tmp"))); |
| 93 | + assertEquals("other must be an instance of org.carlspring.cloud.storage.s3fs.S3Path or a relative Path", e.getMessage()); |
| 94 | + } |
67 | 95 | }
|
0 commit comments