use of org.junit.rules.TemporaryFolder in project ddf by codice.
the class AdminDocsModuleTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException {
tempFolder = new TemporaryFolder();
tempFolder.create();
mockDdfHome = tempFolder.newFolder("ddf");
System.setProperty("karaf.home", mockDdfHome.getPath());
}
use of org.junit.rules.TemporaryFolder in project flow by vaadin.
the class StaticFileServerTest method openingJarFileSystemForDifferentFilesInSameJar_existingFileSystemIsUsed.
@Test
public void openingJarFileSystemForDifferentFilesInSameJar_existingFileSystemIsUsed() throws IOException, URISyntaxException {
Assert.assertTrue("Can not run concurrently with other test", StaticFileServer.openFileSystems.isEmpty());
final TemporaryFolder folder = TemporaryFolder.builder().build();
folder.create();
Path tempArchive = generateZipArchive(folder);
final URL folderResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/frontend");
final URL fileResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/file.txt");
fileServer.getFileSystem(folderResourceURL.toURI());
fileServer.getFileSystem(fileResourceURL.toURI());
Assert.assertEquals("Same file should be marked for both resources", (Integer) 2, StaticFileServer.openFileSystems.entrySet().iterator().next().getValue());
fileServer.closeFileSystem(folderResourceURL.toURI());
Assert.assertEquals("Closing resource should be removed from jar uri", (Integer) 1, StaticFileServer.openFileSystems.entrySet().iterator().next().getValue());
fileServer.closeFileSystem(fileResourceURL.toURI());
Assert.assertTrue("Closing last resource should clear marking", StaticFileServer.openFileSystems.isEmpty());
try {
FileSystems.getFileSystem(folderResourceURL.toURI());
Assert.fail("Jar FileSystem should have been closed");
} catch (FileSystemNotFoundException fsnfe) {
// This should happen as we should not have an open FileSystem here.
}
}
use of org.junit.rules.TemporaryFolder in project flow by vaadin.
the class StaticFileServerTest method directoryIsNotResourceRequest.
@Test
public void directoryIsNotResourceRequest() throws Exception {
fileServer.writeResponse = false;
final TemporaryFolder folder = TemporaryFolder.builder().build();
folder.create();
setupRequestURI("", "", "/frontend");
// generate URL so it is not ending with / so that we test the correct
// method
String rootAbsolutePath = folder.getRoot().getAbsolutePath().replaceAll("\\\\", "/");
if (rootAbsolutePath.endsWith("/")) {
rootAbsolutePath = rootAbsolutePath.substring(0, rootAbsolutePath.length() - 1);
}
final URL folderPath = new URL("file:///" + rootAbsolutePath);
Mockito.when(servletService.getStaticResource("/frontend")).thenReturn(folderPath);
Assert.assertFalse("Folder on disk should not be a static resource.", fileServer.serveStaticResource(request, response));
// Test any path ending with / to be seen as a directory
setupRequestURI("", "", "/fake");
Mockito.when(servletService.getStaticResource("/fake")).thenReturn(new URL("file:///fake/"));
Assert.assertFalse("Fake should not check the file system nor be a static resource.", fileServer.serveStaticResource(request, response));
Path tempArchive = generateZipArchive(folder);
setupRequestURI("", "", "/frontend/.");
Mockito.when(servletService.getStaticResource("/frontend/.")).thenReturn(new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/frontend"));
Assert.assertFalse("Folder 'frontend' in jar should not be a static resource.", fileServer.serveStaticResource(request, response));
setupRequestURI("", "", "/file.txt");
Mockito.when(servletService.getStaticResource("/file.txt")).thenReturn(new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/file.txt"));
Assert.assertTrue("File 'file.txt' inside jar should be a static resource.", fileServer.serveStaticResource(request, response));
folder.delete();
}
use of org.junit.rules.TemporaryFolder in project flow by vaadin.
the class StaticFileServerTest method openFileServerExistsForZip_openingNewDoesNotFail.
@Test
public void openFileServerExistsForZip_openingNewDoesNotFail() throws IOException, URISyntaxException {
Assert.assertTrue("Can not run concurrently with other test", StaticFileServer.openFileSystems.isEmpty());
final TemporaryFolder folder = TemporaryFolder.builder().build();
folder.create();
Path tempArchive = generateZipArchive(folder);
final FileSystem fileSystem = FileSystems.newFileSystem(new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/").toURI(), Collections.emptyMap());
final URL folderResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/frontend");
try {
fileServer.getFileSystem(folderResourceURL.toURI());
} finally {
fileServer.closeFileSystem(folderResourceURL.toURI());
fileSystem.close();
}
}
use of org.junit.rules.TemporaryFolder in project flow by vaadin.
the class DevModeInitializerTest method onStartup_fallbackBaseDirIsGradleProjectDirectory_isAccepted.
@Test
public void onStartup_fallbackBaseDirIsGradleProjectDirectory_isAccepted() throws Exception {
Mockito.when(appConfig.getStringProperty(FrontendUtils.PROJECT_BASEDIR, null)).thenReturn(null);
TemporaryFolder tmp = new TemporaryFolder();
tmp.create();
tmp.newFile("build.gradle");
baseDir = tmp.getRoot().getPath();
String originalUserDirValue = null;
try {
originalUserDirValue = System.getProperty("user.dir");
System.setProperty("user.dir", baseDir);
devModeStartupListener.onStartup(classes, servletContext);
} finally {
if (originalUserDirValue != null) {
System.setProperty("user.dir", originalUserDirValue);
}
}
}
Aggregations