|
18 | 18 | import com.spectralogic.ds3client.utils.Platform; |
19 | 19 | import org.apache.commons.io.FileUtils; |
20 | 20 | import org.junit.Assume; |
| 21 | +import org.junit.Rule; |
21 | 22 | import org.junit.Test; |
| 23 | +import org.junit.rules.TemporaryFolder; |
22 | 24 |
|
23 | 25 | import java.io.IOException; |
| 26 | +import java.nio.ByteBuffer; |
| 27 | +import java.nio.channels.SeekableByteChannel; |
24 | 28 | import java.nio.file.Files; |
25 | 29 | import java.nio.file.Path; |
26 | 30 | import java.nio.file.Paths; |
27 | 31 | import java.util.concurrent.atomic.AtomicBoolean; |
28 | 32 |
|
29 | 33 | import static org.junit.Assert.assertFalse; |
30 | 34 | import static org.junit.Assert.assertTrue; |
| 35 | +import static org.junit.Assert.fail; |
31 | 36 |
|
32 | 37 | public class FileObjectGetter_Test { |
| 38 | + @Rule |
| 39 | + public TemporaryFolder temporaryFolder = new TemporaryFolder(); |
| 40 | + |
33 | 41 | @Test |
34 | 42 | public void testThatNamedPipeThrows() throws IOException, InterruptedException { |
35 | 43 | Assume.assumeFalse(Platform.isWindows()); |
@@ -77,4 +85,27 @@ public void testThatFileReportsAsRegularOnWindows() throws IOException, Interrup |
77 | 85 |
|
78 | 86 | assertFalse(caughtException.get()); |
79 | 87 | } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testThatSymbolicLinksAreResolved() { |
| 91 | + Assume.assumeTrue(Platform.isMac()); |
| 92 | + final String message = "Hello World"; |
| 93 | + final String file = "file.txt"; |
| 94 | + try { |
| 95 | + final Path tempDirectory = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "ds3"); |
| 96 | + final Path realDirectory = Files.createDirectory(Paths.get(tempDirectory.toString(), "dir")); |
| 97 | + final Path symbolicDirectory = Paths.get(tempDirectory.toString(), "symbolic"); |
| 98 | + Files.createSymbolicLink(symbolicDirectory, realDirectory); |
| 99 | + Files.createFile(Paths.get(realDirectory.toString(), file)); |
| 100 | + final ByteBuffer bb = ByteBuffer.wrap(message.getBytes()); |
| 101 | + |
| 102 | + final SeekableByteChannel getterChannel = new FileObjectGetter(symbolicDirectory).buildChannel(file); |
| 103 | + getterChannel.write(bb); |
| 104 | + getterChannel.close(); |
| 105 | + final String content = new String(Files.readAllBytes(Paths.get(realDirectory.toString(), file))); |
| 106 | + assertTrue(message.equals(content)); |
| 107 | + } catch (final IOException e) { |
| 108 | + fail("Symbolic links are not handled correctly"); |
| 109 | + } |
| 110 | + } |
80 | 111 | } |
0 commit comments