private void testFSProps(String fileName, Handler<FileSystemProps> afterOK) throws Exception { vertx.fileSystem().fsProps(testDir + pathSep + fileName, ar -> { if (ar.failed()) { fail(ar.cause().getMessage()); } else { afterOK.handle(ar.result()); testComplete(); } }); }
@Test public void testReadFileInDirThenReadDir() { Buffer buff = vertx.fileSystem().readFileBlocking("webroot/subdir/subfile.html"); assertEquals(buff.toString(), "<html><body>subfile</body></html>"); Set<String> names = vertx.fileSystem().readDirBlocking("webroot/subdir").stream().map(path -> { int idx = path.lastIndexOf(File.separator); return idx == -1 ? path : path.substring(idx + 1); }).collect(Collectors.toSet()); assertEquals(names, new HashSet<>(Arrays.asList("subdir2", "subfile.html"))); }
private void testLink(String from, String to, boolean symbolic, boolean shouldPass, Handler<Void> afterOK) throws Exception { if (symbolic) { // Symlink is relative vertx.fileSystem().symlink(testDir + pathSep + from, to, createHandler(shouldPass, afterOK)); } else { vertx.fileSystem().link(testDir + pathSep + from, testDir + pathSep + to, createHandler(shouldPass, afterOK)); } }
private void testCopy(String source, String target, boolean recursive, boolean shouldPass, Handler<Void> afterOK) { if (recursive) { vertx.fileSystem().copyRecursive(testDir + pathSep + source, testDir + pathSep + target, true, createHandler(shouldPass, afterOK)); } else { vertx.fileSystem().copy(testDir + pathSep + source, testDir + pathSep + target, createHandler(shouldPass, afterOK)); } }
private void testDelete(String fileName, boolean recursive, boolean shouldPass, Handler<Void> afterOK) throws Exception { if (recursive) { vertx.fileSystem().deleteRecursive(testDir + pathSep + fileName, recursive, createHandler(shouldPass, afterOK)); } else { vertx.fileSystem().delete(testDir + pathSep + fileName, createHandler(shouldPass, afterOK)); } }
@Test public void testCreateTempDirectoryBlocking() { FileSystem fs = vertx.fileSystem(); String tempDirectory = fs.createTempDirectoryBlocking("project"); assertTrue(Files.exists(Paths.get(tempDirectory))); }
@Test public void testCreateTempDirectoryWithDirectoryBlocking() { FileSystem fs = vertx.fileSystem(); String tempDirectory = fs.createTempDirectoryBlocking(testDir, "project", null); Path path = Paths.get(tempDirectory); assertTrue(Files.exists(Paths.get(tempDirectory))); assertTrue(path.startsWith(testDir)); }
@Test public void testCaPathValue() throws Exception { PemTrustOptions options = Trust.SERVER_PEM.get(); options.getCertPaths(). stream(). map(vertx.fileSystem()::readFileBlocking). forEach(options::addCertValue); options.getCertPaths().clear(); testTrustStore(options); }
@Test public void testCreateTempFileWithDirectoryBlocking() { FileSystem fs = vertx.fileSystem(); String tempFile = fs.createTempFileBlocking(testDir, "project", ".tmp", null); assertNotNull(tempFile); Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); assertTrue(path.startsWith(testDir)); }
@Test public void testFileSystemReadFile() { assertTrue(vertx.fileSystem().existsBlocking("afile.html")); assertFalse(vertx.fileSystem().propsBlocking("afile.html").isDirectory()); Buffer buffer = vertx.fileSystem().readFileBlocking("afile.html"); assertNotNull(buffer); assertTrue(buffer.toString().startsWith("<html><body>afile</body></html>")); }
@Test public void testFileSystemReadDirectory() { assertTrue(vertx.fileSystem().existsBlocking("webroot")); assertTrue(vertx.fileSystem().propsBlocking("webroot").isDirectory()); }
@Test public void testCreateTempDirectoryWithDirectory() { FileSystem fs = vertx.fileSystem(); fs.createTempDirectory(testDir, "project", null, onSuccess(tempDirectory -> { Path path = Paths.get(tempDirectory); assertTrue(Files.exists(path)); assertTrue(path.startsWith(testDir)); complete(); })); await(); }
@Test public void testCreateTempFileWithDirectory() { FileSystem fs = vertx.fileSystem(); fs.createTempFile(testDir, "project", ".tmp", null, onSuccess(tempFile -> { assertNotNull(tempFile); Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); assertTrue(path.startsWith(testDir)); complete(); })); await(); }
@Test public void testCreateTempFile() { FileSystem fs = vertx.fileSystem(); fs.createTempFile("project", ".tmp", onSuccess(tempFile -> { assertNotNull(tempFile); assertTrue(Files.exists(Paths.get(tempFile))); complete(); })); await(); }
private void testChownFails(String user) throws Exception { String file1 = "some-file.dat"; createFileWithJunk(file1, 100); vertx.fileSystem().chown(testDir + pathSep + file1, user, null, ar -> { deleteFile(file1); assertTrue(ar.failed()); testComplete(); }); await(); }
@Test public void testCreateTempFileWithPermsBlocking() throws Exception { Assume.assumeFalse(Utils.isWindows()); FileSystem fs = vertx.fileSystem(); String tempFile = fs.createTempFileBlocking("project", ".tmp", DEFAULT_FILE_PERMS); Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); String perms = PosixFilePermissions.toString(Files.getPosixFilePermissions(path)); assertEquals(perms, DEFAULT_FILE_PERMS); } }
@Test public void testUnlink() throws Exception { String fileName = "some-file.txt"; long fileSize = 1234; createFileWithJunk(fileName, fileSize); String linkName = "some-link.txt"; Files.createLink(Paths.get(testDir + pathSep + linkName), Paths.get(testDir + pathSep + fileName)); assertEquals(fileSize, fileLength(linkName)); vertx.fileSystem().unlink(testDir + pathSep + linkName, createHandler(true, v -> assertFalse(fileExists(linkName)))); await(); }
@Test public void testKeyCertValue() throws Exception { PemKeyCertOptions options = Cert.SERVER_PEM.get(); Buffer key = vertx.fileSystem().readFileBlocking(options.getKeyPath()); options.setKeyValue(null).setKeyValue(key); Buffer cert = vertx.fileSystem().readFileBlocking(options.getCertPath()); options.setCertValue(null).setCertValue(cert); testKeyStore(options); }
@Test public void testWriteEmptyAsync() throws Exception { String fileName = "some-file.dat"; vertx.fileSystem().open(testDir + pathSep + fileName, new OpenOptions(), onSuccess(file -> { file.write(Buffer.buffer(), 0, onSuccess(v -> { testComplete(); })); })); await(); }
@Test public void testJKSValue() throws Exception { JksOptions options = Cert.SERVER_JKS.get(); Buffer store = vertx.fileSystem().readFileBlocking(options.getPath()); options.setPath(null).setValue(store); testKeyStore(options); }