@Test public void testRecursivelyUnpack2() throws Exception { File file = resolver.resolveFile(webRoot + "/subdir"); assertTrue(file.exists()); File sub = new File(new File(file, "subdir2"), "subfile2.html"); assertTrue(sub.exists()); assertEquals("<html><body>subfile2</body></html>", readFile(sub)); }
@Test public void testResolveSubDirectoryFromClasspath() throws Exception { for (int i = 0; i < 2; i++) { File file = resolver.resolveFile(webRoot + "/subdir"); assertTrue(file.exists()); assertTrue(file.getPath().startsWith(".vertx" + File.separator + "file-cache-")); assertTrue(file.isDirectory()); } }
@Test public void testResolveFileFromClasspath() throws Exception { for (int i = 0; i < 2; i++) { File file = resolver.resolveFile("afile.html"); assertTrue(file.exists()); assertTrue(file.getPath().startsWith(".vertx" + File.separator + "file-cache-")); assertFalse(file.isDirectory()); assertEquals("<html><body>afile</body></html>", readFile(file)); } }
@Test public void testDeleteCacheDir() throws Exception { Vertx vertx2 = vertx(); FileResolver resolver2 = new FileResolver(vertx2); File file = resolver2.resolveFile(webRoot + "/somefile.html"); assertTrue(file.exists()); File cacheDir = file.getParentFile().getParentFile(); assertTrue(cacheDir.exists()); resolver2.close( onSuccess( res -> { assertFalse(cacheDir.exists()); vertx2.close( res2 -> { testComplete(); }); })); await(); }
@Override protected void tearDown() throws Exception { CountDownLatch latch = new CountDownLatch(1); resolver.close( onSuccess( res -> { latch.countDown(); })); awaitLatch(latch); super.tearDown(); }
@Test public void testResolveFileFromClasspathDisableCaching() throws Exception { System.setProperty(FileResolver.DISABLE_FILE_CACHING_PROP_NAME, "true"); resolver = new FileResolver(vertx); for (int i = 0; i < 2; i++) { File file = resolver.resolveFile("afile.html"); assertTrue(file.exists()); assertTrue(file.getPath().startsWith(".vertx" + File.separator + "file-cache-")); assertFalse(file.isDirectory()); assertEquals("<html><body>afile</body></html>", readFile(file)); } }
@Test public void testResolveNotExistFileInDirectory() { File file = resolver.resolveFile("somedir/doesnotexist.txt"); assertFalse(file.exists()); assertEquals("somedir" + File.separator + "doesnotexist.txt", file.getPath()); }
@Test public void testResolveNotExistDirectory() { File file = resolver.resolveFile("somedir"); assertFalse(file.exists()); assertEquals("somedir", file.getPath()); }
@Test public void testResolveNotExistFile() { File file = resolver.resolveFile("doesnotexist.txt"); assertFalse(file.exists()); assertEquals("doesnotexist.txt", file.getPath()); }