Search in sources :

Example 36 with TemporaryFolder

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());
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) BeforeClass(org.junit.BeforeClass)

Example 37 with TemporaryFolder

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.
    }
}
Also used : Path(java.nio.file.Path) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) TemporaryFolder(org.junit.rules.TemporaryFolder) URL(java.net.URL) Test(org.junit.Test)

Example 38 with TemporaryFolder

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();
}
Also used : Path(java.nio.file.Path) TemporaryFolder(org.junit.rules.TemporaryFolder) URL(java.net.URL) Test(org.junit.Test)

Example 39 with TemporaryFolder

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();
    }
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) TemporaryFolder(org.junit.rules.TemporaryFolder) URL(java.net.URL) Test(org.junit.Test)

Example 40 with TemporaryFolder

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);
        }
    }
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) Test(org.junit.Test)

Aggregations

TemporaryFolder (org.junit.rules.TemporaryFolder)88 File (java.io.File)33 Test (org.junit.Test)25 Before (org.junit.Before)24 BeforeClass (org.junit.BeforeClass)13 Path (java.nio.file.Path)7 URL (java.net.URL)6 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 UserState (alluxio.security.user.UserState)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 RocksDBPersistenceProvider (com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider)2 DocumentMetaData (de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URISyntaxException (java.net.URISyntaxException)2 BdpDataPlanePlugin (org.batfish.bdp.BdpDataPlanePlugin)2 Batfish (org.batfish.main.Batfish)2 DefaultSafeModeManager (alluxio.master.DefaultSafeModeManager)1 InMemoryReferenceSequenceFile (au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile)1 SynchronousReferenceLookupAdapter (au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter)1