X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fext%2Ftest%2Forg%2Fargeo%2Fjcr%2Ffs%2FJcrFileSystemTest.java;h=e24a7de9ff2e00e0783f57fa71e93893d1c2a689;hb=d4a5631f933282d791fb8edddc59a6f6751311e0;hp=1cf7ef70e9573e0a4c99e91c2d59175eaea50026;hpb=d8037dd6a59ff5d38d7c7182a9ef6c26c8001a4f;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java b/org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java index 1cf7ef70e..e24a7de9f 100644 --- a/org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java +++ b/org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java @@ -29,7 +29,18 @@ public class JcrFileSystemTest extends TestCase { FileSystemProvider fsProvider = new JackrabbitMemoryFsProvider(); // Simple file + Path rootPath = fsProvider.getPath(new URI("jcr+memory:/")); + log.debug("Got root " + rootPath); Path testPath = fsProvider.getPath(new URI("jcr+memory:/test.txt")); + log.debug("Test path"); + assertEquals("test.txt", testPath.getFileName().toString()); + assertEquals(rootPath, testPath.getParent()); + assertEquals(testPath.getFileName(), rootPath.relativize(testPath)); + // relativize self should be empty path + Path selfRelative = testPath.relativize(testPath); + assertEquals("", selfRelative.toString()); + + log.debug("Create file " + testPath); Files.createFile(testPath); BasicFileAttributes bfa = Files.readAttributes(testPath, BasicFileAttributes.class); FileTime ft = bfa.creationTime(); @@ -46,8 +57,6 @@ public class JcrFileSystemTest extends TestCase { assertTrue(Arrays.equals(arr, read)); assertEquals(txt, new String(read)); log.debug("Read " + testPath); - Path rootPath = fsProvider.getPath(new URI("jcr+memory:/")); - log.debug("Got root " + rootPath); Path testDir = rootPath.resolve("testDir"); log.debug("Resolved " + testDir); // Copy @@ -57,6 +66,9 @@ public class JcrFileSystemTest extends TestCase { log.debug("Created sub directories " + subsubdir); Path copiedFile = testDir.resolve("copiedFile.txt"); log.debug("Resolved " + copiedFile); + Path relativeCopiedFile = testDir.relativize(copiedFile); + assertEquals(copiedFile.getFileName().toString(), relativeCopiedFile.toString()); + log.debug("Relative copied file " + relativeCopiedFile); try (OutputStream out = Files.newOutputStream(copiedFile); InputStream in = Files.newInputStream(testPath)) { IOUtils.copy(in, out); } @@ -94,4 +106,24 @@ public class JcrFileSystemTest extends TestCase { assertEquals(6, attrs.size()); log.debug("Read attributes of " + copiedFile + ": " + attrs.keySet()); } + + public void testIllegalCharacters() throws Exception { + FileSystemProvider fsProvider = new JackrabbitMemoryFsProvider(); + String fileName = "tüßçt[1].txt"; + String pathStr = "/testDir/" + fileName; + Path testDir = fsProvider.getPath(new URI("jcr+memory:/testDir")); + Files.createDirectory(testDir); + Path testPath = testDir.resolve(fileName); + assertEquals(pathStr, testPath.toString()); + Files.createFile(testPath); + DirectoryStream files = Files.newDirectoryStream(testDir); + Path listedPath = files.iterator().next(); + assertEquals(pathStr, listedPath.toString()); + + String dirName = "*[~WeirdDir~]*"; + Path subDir = testDir.resolve(dirName); + Files.createDirectory(subDir); + subDir = testDir.resolve(dirName); + assertEquals(dirName, subDir.getFileName().toString()); + } }